[RESOLVED] Use String To Call DLL Function
Hey again. :wave:
I'm trying to call a dll function now, from a spitted string. I'll explain a little in detail of what I mean.
I have my program load a "Template" from an XML file. The XML lines contain:
"Name", "ID", and "DLLCall". The Name of the XML line is the Class File in the DLL. The DLLCall is the function within that Class.
So for example I have this in my XML file:
Code:
<Template>
<Section Name="User" DLLCall="User">
<Item Name="User Name" DLLCall="User_Name">
</Section>
</Template>
The program will read that and see the section User will use the class file "User" inside the dll. From that the item name to get the User Name will use the function "User_Name" inside the User Class file.
I have my own little parser I wrote for the program to put these together as one string (like the dll call would look like.) So the call becomes:
Code:
MyDLL.User.User_Name
The problem is, is this is stored in a string. And its not actually being used to call the DLL function. Is there anyway I can take the string that holds the DLL function and call the DLL function with that string?
(If you need more details, or a better explination, I can try..)
Re: Use String To Call DLL Function
From what I understand I guess you can try CallbyName
Re: Use String To Call DLL Function
Quote:
Originally Posted by Shuja Ali
From what I understand I guess you can try
CallbyName
Thanks for the quick reply. I tried using CallByName for this already and it gives errors no matter how I try to use the function. What I try to do with it is this:
Since Im trying to get a value I use the vbGet method with this..
VB Code:
ReturnValue = CallByName(MyDLL, FuncString, vbGet)
To explain my variables, MyDLL is the object. Set in the form load like this:
VB Code:
Set MyDLL = CreateObject("MyDLL.StartClass")
The way my DLL is coded uses StartClass to get the correct properties and class files within the dll. I have MyDLL globaly declared as an object for this as well.
Within my "parser function", Im splitting the XML returns to get the actual DLL function call. FuncString, for example, would equal User.User_Name. The full DLL call would be:
MyDLL.User.User_Name
This will return a string value if its called. Now if I try using the CallByName like I showed above I get this error:
Code:
Object doesnt support this property or method.
But if I call it myself without that code like this:
VB Code:
ResultValue = MyDLL.User.User_Name
it works fine.
Re: Use String To Call DLL Function
Actually, I needed to build a select case statement to get this to work correctly. I needed to make a select case statement to see which class file they were asking for then set the CallByName for that class file. Something like this:
VB Code:
Select Case ClassFile
Case = "User"
ResultValue = CallByName(MyDLL.User, CallProc, vbGet)
Case = "Info"
ResultValue = CallByName(MyDLL.Info, CallProc, vbGet)
End Select
And it works now.
==========================
Nvm the edit, fixed it. Was a small mistake on my part. Works great now.