Click here to Skip to main content
15,886,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I tried calling a function from a vb dotnet dll(from a cpp dll),
this is my code
C++
#include "main.h"
#include <windows.h>
#include <mscoree.h>
#pragma comment(lib,"mscoree.lib")
void DLL_EXPORT SomeFunction()
{
        ICLRRuntimeHost *pClrHost = NULL;
        HRESULT hr = CorBindToRuntimeEx(
        NULL, L"wks", 0, CLSID_CLRRuntimeHost,
        IID_ICLRRuntimeHost, (PVOID*)&pClrHost);
        hr = pClrHost->Start();
        DWORD dwRet = 0;
        hr = pClrHost->ExecuteInDefaultAppDomain(
             L"message.dll",
             L"message.Class1", L"message", L"Hello", &dwRet);
}

extern "C" DLL_EXPORT BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
            // attach to process
            // return FALSE to fail DLL load
            break;

        case DLL_PROCESS_DETACH:
            // detach from process
            break;

        case DLL_THREAD_ATTACH:
            // attach to thread
            break;

        case DLL_THREAD_DETACH:
            // detach from thread
            break;
    }
    return TRUE; // succesful
}

the dotnet code is
Public Class Class1
    Function message(ByVal a As String)
        MsgBox(a)
    End Function
End Class

when i try calling SomeFunction using ExecDLL.exe nothing happens
am using codeblocks
compiler is MS visual C++ 2005/2008
Posted
Comments
Richard MacCutchan 31-May-13 3:38am    
You are capturing the return codes from the API calls but ignoring them. Add some proper error checking and run your code in the debugger to see what is happening.
RaMMicHaeL 31-May-13 4:15am    
how to run a dll from inside codeblocks?
if i try to run the dll from ExecDLL.exe it just freezes if i click the execute button more than once
Richard MacCutchan 31-May-13 5:21am    
Read my previous comment again, with particulr reference to error checking and using the debugger.
RaMMicHaeL 31-May-13 23:41pm    
how to run a dll from inside codeblocks?
Richard MacCutchan 1-Jun-13 4:01am    
You don't run a dll. A dll is a library that is linked to by an exe program.

1 solution

Hi
Why you don`t used C++/CLI for this purpose? I suggest to you use if because CLI technology provide a really good environment and falsity to the simultaneous use of native and managed code. for getting more information about it please follow of links:

Using .net 4 library from MFC applications[^]

and you can use .net forms and controls from MFC or C++ if you want get the information about it you can go:

How to Host Windows Form in Windows User Control[^]
Hosting Windows Forms User Control in MFC Dialogs[^]

Best Regards.
 
Share this answer
 

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