Search code examples
visual-c++dllvb6dllimport

How to call Vb6 dll on VC++ without the header


Is there a way for me to use a dll that come from a VB6 application o VSC++ without the header file? I have the dll and the .lib and was trying to do the following for loading the dll.

    FunctionCalledType calledPTR = NULL;
    hDLL = LoadLibrary(_T("called.dll"));
    if (hDLL == NULL) {
        std::cerr << "DLL called.dll could not be found!";
        return 2;
    }
    calledPTR = (FunctionCalledType)GetProcAddress(hDLL, "FunctionCalled");
    if (NULL != calledPTR)
    {
        std::cout << "Got Function";
        calledPTR("fileA.bz", "fileA.txt");
    }
    else{
        std::cerr << "Didn't got function";
        return 3;
    }
    return 0;

The code runs fine but i get a memory access error on

        calledPTR("fileA.bz", "fileA.txt");

in which FunctionCalledType is defined as follow:

 typedef string(CALLBACK* FunctionCalledType)(string, string);

And the VB6 code that generated the dll is the following :

        Public Function FunctionCalled(src As String, dest As String) As String

           //Some code

        End Function

I guess my pointer to the function is on the wrong format, or i am including the dll on the wrong way


Solution

  • These are the 4 exported functions a VB6.dll has.

    DllCanUnloadNow
    DllGetClassObject
    DllRegisterServer
    DllUnregisterServer
    

    If your code is in a class module you create a object based on VB6's class module then call the function as a method.

    It's good you don't want to learn COM. There is almost no chance of this working.