Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.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# ';调用PInvoke函数..';c+错误+;c语言的DLL方法# 我必须使用C++代码中的C++项目中的DLL函数。_C#_C++_Dllimport - Fatal编程技术网

C# ';调用PInvoke函数..';c+错误+;c语言的DLL方法# 我必须使用C++代码中的C++项目中的DLL函数。

C# ';调用PInvoke函数..';c+错误+;c语言的DLL方法# 我必须使用C++代码中的C++项目中的DLL函数。,c#,c++,dllimport,C#,C++,Dllimport,C++: 我使用DllImport导入如下内容: C#: 当我调用'ReadString'函数时,它会显示标准的'A call to PInvoke function'[…]”出现了“堆栈不平衡”错误 public string fooNameFunction(string strNAME, string strDefaultValue, int pathKey = Constants.REG_SUBT_TEMP, string serverName = null, long stnNumber

C++:

我使用DllImport导入如下内容:

C#:

当我调用'ReadString'函数时,它会显示标准的'A call to PInvoke function'[…]”出现了“堆栈不平衡”错误

public string fooNameFunction(string strNAME, string strDefaultValue, int pathKey = Constants.REG_SUBT_TEMP, string serverName = null, long stnNumber = 0)
    long lRegReturnValue;
    lRegReturnValue = ReadString(strNAME, strValue, strDefaultValue, pathKey, serverName, stnNumber); //error here
    return ""; //has nothing to do with my error
}
我已经尝试调用Convention.Cdecl,但错误仍然存在


在Windows中C++中,

<代码>长< /COD>是32位,而<代码>长< /C> > C中为64位。所以
stnNumber
应该是
int
。返回值也应该是
int
,非零值表示true。这也有点像代码期望将一些文本参数返回给调用方。那需要<代码> StringBuilder <代码>,以及如何分配一个缓冲区的一些概念。@ DavidHeffernan,谢谢,我不知道C++中的<代码>长< /Cord>大小(我的坏)。
[DllImport("DHRegistry.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
static extern long ReadString([MarshalAs(UnmanagedType.LPTStr)] string valueName,
                              [MarshalAs(UnmanagedType.LPTStr)] string value,
                              [MarshalAs(UnmanagedType.LPTStr)] string defaultValue,
                              [MarshalAs(UnmanagedType.I4)] int subTree,
                              [MarshalAs(UnmanagedType.LPTStr)] string serverName,
                              [MarshalAs(UnmanagedType.I8)] long stnNumber);
public string fooNameFunction(string strNAME, string strDefaultValue, int pathKey = Constants.REG_SUBT_TEMP, string serverName = null, long stnNumber = 0)
    long lRegReturnValue;
    lRegReturnValue = ReadString(strNAME, strValue, strDefaultValue, pathKey, serverName, stnNumber); //error here
    return ""; //has nothing to do with my error
}