我想请教一下如何从C调用DLL VB.NET ++程序如何从C调用DLL VB.NET ++(呼叫功能也 - 不只是DLL文件)
我已经尝试了很多次调用问题VB.NET DLL文件从C + +和它工作正常,但问题是我不能调用VB.NET DLL文件的功能(我只能加载VB.NET DLL文件)
in VB.NET DLL我有以下代码:
Public Function example_function1(ByVal i As Integer) As Integer
Return 3
End Function
Public Function example_function2(ByVal i As Integer) As Integer
Return 3
End Function
============================
我的C++代码是:
typedef int (__stdcall *ptf_test_func_1_type)(int);
typedef int (__stdcall *ptf_test_func_2_type)(int*);
int i =1;
HINSTANCE dll_instance = LoadLibrary("DLLs7.dll");
int main()
{
if(dll_instance !=NULL)
{
printf("The DLLs file has been Loaded \n");
cout << GetLastError() << endl;
ptf_test_func_1_type p_func1=(ptf_test_func_1_type)GetProcAddress(dll_instance,"Class1::example_function1");
ptf_test_func_2_type p_func2=(ptf_test_func_2_type)GetProcAddress(dll_instance,"Class1::example_function2");
// Function No 1 //
if (p_func1 != NULL)
{
cout << "\nThe function number 1 is " << p_func1(i) << endl;
}
else
{
cout << "\nFailed" << endl;
cout << GetLastError() << endl;
}
// Function No 2 //
if (p_func2 != NULL)
{
cout << "\nThe function number 2 is" << p_func2(&i) << endl;
}
else
{
cout << "\nFailed" << endl;
cout << GetLastError() << endl;
}
}
else
{
printf("\nDLLs file Load Error");
cout << GetLastError() << endl;
}
cout << GetLastError() << endl;
return(0);
}
我的下列步骤是:
1)我已经创建VB.NET DLL。
2)I已经创建了一个新的应用程序Visual C++和
3)I所编写的代码来调用DLL和功能(如你可以在上面看到)
选择“Win32控制台应用程序”我错过了在步骤或代码,任何东西,因为我可以调用VB.NET DLL文件,但我不能调用VB.NET的DLL函数
,你可以看到我写的GETLASTERRIR()来找到错误
cout < < GetLastError()< < endl;
,但我发现这个错误127在函数失败时,并在调用DLL文件203
谁能帮助我
非常感谢您
问候
错误127名的意思是“指定的程序无法找到”。 VB.NET不能导出这样的函数。您将需要使用COM(使用属性)或使用C++/CLI语言编写包装类。需要此粘合剂才能使CLR初始化,以便您的程序可以执行托管代码。 –
2011-05-13 12:47:18