Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
typedef int (FAR PASCAL *RUNSCRIPT_FUNCTION)(int, LPCSTR);

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
{
    RUNSCRIPT_FUNCTION  RunScript;
    int  iReturn;

    // Load the DLL
    HINSTANCE hinstLib = LoadLibrary("C:\\Program Files\\Example.dll");
    if(hinstLib == NULL)
    {
        MessageBox(NULL, "Unable to load library", "Error", MB_OK|MB_ICONERROR);
        return 0;
    }

    // Get the function pointer
    RunScript = (RUNSCRIPT_FUNCTION)GetProcAddress(hinstLib, "RunScript");
    if(RunScript == NULL)
    {
        FreeLibrary(hinstLib);
       
        return 0;
    }
    
    // Call the function with '1' as a parameter
    iReturn = (*RunScript)(1, "Hello");

    // Unload the DLL
    FreeLibrary(hinstLib);
    
    return iReturn;
}


What I have tried:

I am not able to call methods in visual c++,class and methods are present in dll and dll is unmanaged.
Posted
Updated 14-Mar-17 4:02am
Comments
[no name] 14-Mar-17 8:44am    
https://www.google.com/search?q=c%2B%2B+calling+c%23+dll

1 solution

That shouldnt be a big problem, but you must pay attention to string (and memory) issue. Use for the call of your dll a _bstr_t. Ihe usage is explained this article.

If you work with the string in the C# runtime you need to make a copy.

Tip: you can set breakpoints in the C# dll for debugging if the dll is a debug build.
 
Share this answer
 
Comments
Member 10936477 15-Mar-17 0:53am    
sorry may be i am not able to make you understand, my problem is,i was calling c# dll in visual c++ and not able to pass parameter or call methods.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900