在我的一个解决方案中,我遇到了一个非常奇怪的行为,我需要帮助来解决这个问题。
我在Visual Studio 2015上使用C。
我有一个类库项目,它有以下内容:
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
static extern int GetWindowTextLength(IntPtr hWnd);
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
static extern long GetClassName(IntPtr hwnd, StringBuilder lpClassName, long nMaxCount);
string getHWNDCaption(IntPtr hwnd)
{
if (hwnd == IntPtr.Zero) throw new Exception("getHWNDCaption: Invalid pointer!");
string caption = "";
StringBuilder windowText = null;
try
{
int max_length = GetWindowTextLength(hwnd);
windowText = new StringBuilder("", max_length + 50);
GetWindowText(hwnd, windowText, max_length + 2);
.....
string getHWNDClassName(IntPtr hwnd)
{
if (hwnd == IntPtr.Zero) throw new Exception("ExternalWindowsInfo not initiated!");
string className = "";
StringBuilder classText = null;
try
{
int cls_max_length = 1000;
classText = new StringBuilder("", cls_max_length + 5);
GetClassName(hwnd, classText, cls_max_length + 2);
.......
在旧的Windows窗体项目中,我执行这些函数,它们返回所需的数据。
我试图将新的Windows窗体项目添加到相同的解决方案中,在执行相同的函数时,我收到以下错误,这是我无法超越的:
A call to PInvoke function ...::GetWindowTextLength' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
当我使用相同的代码时,我相信它在项目定义中有所体现,但无法找出什么。
任何帮助都将不胜感激!