本文介绍了从代码块中的非托管调用托管代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从vb dotnet dll调用函数(来自cpp dll),

这是我的代码

I tried calling a function from a vb dotnet dll(from a cpp dll),
this is my code

#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
}



.netnet代码是


the dotnet code is

Public Class Class1
    Function message(ByVal a As String)
        MsgBox(a)
    End Function
End Class



当我尝试使用ExecDLL.exe调用SomeFunction时没有任何反应

我正在使用codeblocks

编译器是MS visual C ++ 2005/2008


when i try calling SomeFunction using ExecDLL.exe nothing happens
am using codeblocks
compiler is MS visual C++ 2005/2008

推荐答案


这篇关于从代码块中的非托管调用托管代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 12:38
查看更多