Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
呼叫C++;具有VB.NET中的参数的函数 我得到了这样的C++ dll: #include "stdafx.h" #include <string.h> #include <iostream> using namespace std; BOOL booltest(string info1, string info2, DWORD dword1) { if (dword1 == 5) { return FALSE; } if (!strcmp(info1.c_str(), "hello")) // check if info1 = "hello" { return FALSE; // if so return false } return TRUE; // if not return true } BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; } <DllImport("test.dll", CallingConvention:=CallingConvention.StdCall)> Private Shared Function booltest(<MarshalAs(UnmanagedType.Bool)> ByVal test As Boolean) As Boolean End Function #包括“stdafx.h” #包括 #包括 使用名称空间std; BOOL booltest(字符串信息1、字符串信息2、DWORD dword1) { 如果(dword1==5) { 返回FALSE; } if(!strcmp(info1.c_str(),“hello”)//检查info1=“hello” { return FALSE;//如果是,则返回FALSE } return TRUE;//如果不是,则返回TRUE } BOOL APICENT DllMain(模块HMODULE, 德沃德·乌尔打电话的理由, LPVOID lpReserved ) { 开关(ul\u呼叫原因\u) { 案例DLL\u进程\u附加: 案例DLL\u线程\u连接: 案例DLL\u线程\u分离: 案例DLL\u进程\u分离: 打破 } 返回TRUE; }_C++_Vb.net_Dll_Parameters_Pinvoke - Fatal编程技术网

呼叫C++;具有VB.NET中的参数的函数 我得到了这样的C++ dll: #include "stdafx.h" #include <string.h> #include <iostream> using namespace std; BOOL booltest(string info1, string info2, DWORD dword1) { if (dword1 == 5) { return FALSE; } if (!strcmp(info1.c_str(), "hello")) // check if info1 = "hello" { return FALSE; // if so return false } return TRUE; // if not return true } BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; } <DllImport("test.dll", CallingConvention:=CallingConvention.StdCall)> Private Shared Function booltest(<MarshalAs(UnmanagedType.Bool)> ByVal test As Boolean) As Boolean End Function #包括“stdafx.h” #包括 #包括 使用名称空间std; BOOL booltest(字符串信息1、字符串信息2、DWORD dword1) { 如果(dword1==5) { 返回FALSE; } if(!strcmp(info1.c_str(),“hello”)//检查info1=“hello” { return FALSE;//如果是,则返回FALSE } return TRUE;//如果不是,则返回TRUE } BOOL APICENT DllMain(模块HMODULE, 德沃德·乌尔打电话的理由, LPVOID lpReserved ) { 开关(ul\u呼叫原因\u) { 案例DLL\u进程\u附加: 案例DLL\u线程\u连接: 案例DLL\u线程\u分离: 案例DLL\u进程\u分离: 打破 } 返回TRUE; }

呼叫C++;具有VB.NET中的参数的函数 我得到了这样的C++ dll: #include "stdafx.h" #include <string.h> #include <iostream> using namespace std; BOOL booltest(string info1, string info2, DWORD dword1) { if (dword1 == 5) { return FALSE; } if (!strcmp(info1.c_str(), "hello")) // check if info1 = "hello" { return FALSE; // if so return false } return TRUE; // if not return true } BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; } <DllImport("test.dll", CallingConvention:=CallingConvention.StdCall)> Private Shared Function booltest(<MarshalAs(UnmanagedType.Bool)> ByVal test As Boolean) As Boolean End Function #包括“stdafx.h” #包括 #包括 使用名称空间std; BOOL booltest(字符串信息1、字符串信息2、DWORD dword1) { 如果(dword1==5) { 返回FALSE; } if(!strcmp(info1.c_str(),“hello”)//检查info1=“hello” { return FALSE;//如果是,则返回FALSE } return TRUE;//如果不是,则返回TRUE } BOOL APICENT DllMain(模块HMODULE, 德沃德·乌尔打电话的理由, LPVOID lpReserved ) { 开关(ul\u呼叫原因\u) { 案例DLL\u进程\u附加: 案例DLL\u线程\u连接: 案例DLL\u线程\u分离: 案例DLL\u进程\u分离: 打破 } 返回TRUE; },c++,vb.net,dll,parameters,pinvoke,C++,Vb.net,Dll,Parameters,Pinvoke,我在一个VB项目的表单上有一个按钮控件,我想通过p/Invoke调用booltest函数。但是我还需要传递参数!显然,托管和非托管之间的数据类型是不同的 有人对此有有效的解决方案或有用的指针吗?我试着这么做已经有一段时间了 谢谢(对英语很抱歉) 编辑: 开始 <DllImport("mydll.dll")> Public Shared Function booltest(...?) As Boolean End Function 作为布尔值的公共共享函数booltest(…?)

我在一个VB项目的表单上有一个按钮控件,我想通过p/Invoke调用booltest函数。但是我还需要传递参数!显然,托管和非托管之间的数据类型是不同的

有人对此有有效的解决方案或有用的指针吗?我试着这么做已经有一段时间了

谢谢(对英语很抱歉)

编辑: 开始

<DllImport("mydll.dll")>
Public Shared Function booltest(...?) As Boolean
End Function

作为布尔值的公共共享函数booltest(…?)
端函数

免责声明:我仍在学习VB.net,所以如果我错了,请不要伤害我


几周前我遇到了类似的问题。首先,确保为DLL添加对项目的引用。然后确保在代码的开头使用“import”语句。之后,您应该能够正常调用函数。

自己解决了这个问题

extern "C" {
    __declspec(dllexport) BOOL __stdcall booltest(BOOL test)
    {
        if (test)
        {
            return FALSE;
        }
        return TRUE;
    }
}
您可以在VB.NET中使用它,如下所示:

#include "stdafx.h"
#include <string.h>
#include <iostream>
using namespace std;

BOOL booltest(string info1, string info2, DWORD dword1)
{
    if (dword1 == 5)
    {
        return FALSE;
    }
    if (!strcmp(info1.c_str(), "hello")) // check if info1 = "hello"
    {
        return FALSE; // if so return false
    }
    return TRUE; // if not return true
}

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}
<DllImport("test.dll", CallingConvention:=CallingConvention.StdCall)>
Private Shared Function booltest(<MarshalAs(UnmanagedType.Bool)> ByVal test As Boolean) As Boolean
End Function
只需确保将DLL放在VB应用程序的启动路径中,这样它就可以找到DLL,并用自己的DLL替换“test.DLL”。可以传递字符串、整数等。。只需在P/Invoke中修改


祝你好运

对不起,我刚才看到了这个,你的回答也没那么糟糕。我刚刚发布了一个解决方案,最终我自己也这么做了,我在这里发布这个解决方案真是浪费了我的时间哈哈,但是谢谢你;)