Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.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++ 从Excel 2016访问DLL 32位get“;Anwendungfehler49“;_C++_Excel_Vba - Fatal编程技术网

C++ 从Excel 2016访问DLL 32位get“;Anwendungfehler49“;

C++ 从Excel 2016访问DLL 32位get“;Anwendungfehler49“;,c++,excel,vba,C++,Excel,Vba,我从32位Excel 2016中得到一个“Anwendungsfehler 49”调用32位版本的dll。Excel64位和64位版本的dll工作正常。dll中的Messagebox如图所示,但在此之后返回时出错。有人对此有想法吗 这是我的dll代码: // dllmain.cpp : Definiert den Einstiegspunkt für die DLL-Anwendung. #include "pch.h" #include <iostream>

我从32位Excel 2016中得到一个“Anwendungsfehler 49”调用32位版本的dll。Excel64位和64位版本的dll工作正常。dll中的Messagebox如图所示,但在此之后返回时出错。有人对此有想法吗

这是我的dll代码:

// dllmain.cpp : Definiert den Einstiegspunkt für die DLL-Anwendung.
#include "pch.h"
#include <iostream>

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

TEST_API long myTestFunction(LPCSTR test)
{
    size_t origsize = strlen(test) + 1;
    const size_t newsize = 100;
    size_t convertedChars = 0;
    wchar_t wcstring[newsize];
    mbstowcs_s(&convertedChars, wcstring, origsize, test, _TRUNCATE);
    wcscat_s(wcstring, L" (wchar_t *)");
    
    MessageBox(NULL, L"Open the message box ", wcstring, MB_OK | MB_SYSTEMMODAL);
    return (long) 42;
}

// pch.h: 
#ifndef PCH_H
#define PCH_H

// Fügen Sie hier Header hinzu, die vorkompiliert werden sollen.
#include "framework.h"

#endif //PCH_H

#if defined(_MSC_VER)
#include <windows.h>
#define TEST_API extern "C" __declspec(dllexport)
#else
#define TEST_API 
#endif

TEST_API long myTestFunction(LPCSTR test);

必须是
\uu stdcall
,以避免在32位模式下堆栈指针损坏。是的,很好。它与新创建的def文件(用于导出函数)一起工作#如果已定义(_MSC_VER)#包括#定义测试_API(返回类型)外部“C”#定义测试_API(长)myTestFunction(LPCSTR测试);
#If Win64 Then
    Private Declare PtrSafe Function myTestFunction Lib "MyTestDll.dll" (ByVal parameter As String) As Long
#Else
    Private Declare Function myTestFunction Lib "MyTestDll32.dll" (ByVal parameter As String) As Long
#End If
    
Sub Test()
Dim Result As Long
    
Result = myTestFunction("This is a test!")
    
End Sub