Greetings, C++ experts,
Sometimes I wish to expand the possibilities of Visual Basic and thus have to use API. One of the APIs I want to use is GetProcAddress. I can't get a return value other than zero. Thus my question: in which way does a C++ programmer use GetProcAddress?
I studied several MSDN examples and articles. So far this is what I found out:
Its first parameter, hModule, is the handle to a module or library, in my case returned by the LoadLibrary function.
Its second parameter, lpProcName, is the a pointer to a string value holding the name of the wanted procedure.
Now in Visual Basic we can hardly work with pointers. There are two or three functions to create pointers, but they only work if one already has the information I want to get by using GetProcAddress. Pointers are almost useless within Visual Basic. (One could also argue that all referenced parameters in VB already are pointers, but us VB programmers don't know that.) On the other hand, the GetProcAddress declaration for VB allows me to pass a string value to the second parameter instead of a pointer. That's exactly what I use.
So I created a small ocx and a small dll, both owning the same function, let's call it "Default_Function" (It's not THE default function like Dllmain, by the way, and I don't know how to get that one initialised. It should initialise automatically for dlls upon calling LoadLibrary, but I guess VB prevents that from happening). From my application I wish to call this "Default_Function" by passing the string "Default_Function" into the lpProcName parameter of GetProcAddress. Beforehand I checked for the LoadLibrary result and put that into the hModule parameter.
Still, all the GetProcAddress resulted in, was 0.
Therefore, the question once more:
How to use GetProcAddress, how to use it's parameters? Don't answer with MSDN articles, I read them and still can't get a proper result. Please answer from practice and experience.
Being very grateful,