c++ - 32 位 WPF .NET 应用程序找不到其 32 位 dll
问题描述
我使用 P/Invoke,而不是 C++/CLI,并且正在使用 Visual Studio 2017。
我的应用程序是 WPF.NET——32 位,用 C# 编写。当我在我的 PCx64 上运行该应用程序时,它成功加载了它的 32 位 DLL,但是当我在虚拟机(64 或 32)上运行它时它崩溃了。我认为无法添加 DLL ...并且不知道为什么。
我的 DLL 是用 C++ 编写的,包括一个类,其中一些函数是用 Assembler 编写的。问题可能来自于它吗?
我的类.cpp:
int MyClass::Foo_1()
{
__asm
{
mov eax, 0
}
}
void MyClass::SetFoo_1()
{
resultEAX = new int;
int a = -1;
try
{
a = Foo_1();
}
catch (int e) { }
if (a == 0) {
*resultEAX = 0;
}
else {
*resultEAX = 1;
}
}
MyClass.h:
#ifndef MYCLASS_H
#define MYCLASS_H
class __declspec(dllexport) MyClass {
public:
int * resultEAX ;
int Foo1();
void SetFoo_1();
int GetEAX();
};
#endif
MyClassCaller.h:
extern "C" {
#endif
__declspec(dllexport) MyClass* Create();
__declspec(dllexport) void Dispose(MyClass* a_pObject);
__declspec(dllexport) void SetFoo_1(MyClass* a_pObject);
__eclspec(dllexport) int GetEAX(MyClass* a_pObject);
#ifdef __cplusplus
}
#endif
MyClassCaller.cpp:
Graphics* Create()
{
return new MyClass();
}
void Dispose(MyClass * a_pObject)
{
if (a_pObject != NULL)
{
delete a_pObject;
a_pObject = NULL;
}
}
void SetFoo_1(MyClass * a_pObject)
{
if (a_pObject != nullptr)
{
a_pObject->SetFoo_1();
}
}
int GetEAX(MyClass * a_pObject)
{
if (a_pObject != NULL)
{
return a_pObject->GetEAX();
}
return 0;
}
我使用托管 C# 代码从 WPF.NET 调用该类:
IntPtr pMyClass = MyClassHandling.Create();
Int32 a = 0;
Int64 b = 0;
long c = 0;
long rslt = 0;
try
{
MyClassHandling.SetFoo_1(pMyClass);
if (Environment.Is64BitOperatingSystem)
{
//"SysWOW64"
b = MyClassHandling.GetEAX(pMyClass);
//……
}
else
{
//"system32"
a = pMyClassHandling.GetEAX(pGraphics);
//…
}
MyClassHandling.Dispose (pGraphics);
pMyClass = IntPtr.Zero;
[DllImport("SomeAssemblerFunctions.dll")]
static public extern IntPtr Create();
[DllImport("SomeAssemblerFunctions.dll")]
static public extern void Dispose(IntPtr pGraphicsObject);
[DllImport("SomeAssemblerFunctions.dll", EntryPoint = "SetGraphicMode1")]
static public extern void SetFoo_1(IntPtr pGraphicsObject);
[DllImport("SomeAssemblerFunctions.dll", EntryPoint = "GetEAX")]
static public extern int GetEAX(IntPtr pGraphicsObject);
解决方案
推荐阅读
- r - 将 data.table 与差异行绑定,以便较短的数据集重复最后一行
- c++ - 如何实现信号量?这个实现是正确的还是错误的?
- azure-data-lake - 如何将 ADLS Gen-1 与 Azure ML Studio 连接
- tensorflow - 推理时间 TensorFlow C++ API 与 Python API
- android - 安卓工具:listitem
- reactjs - 如何使用 react-ga 使用谷歌分析根据 React JS 中的用户 ID 跟踪特定用户活动或页面浏览量
- r - 使用来自另一个 DF 的中断对组内的数据进行分箱
- c++ - 为什么移动构造的对象保留了空私有向量的容量,而复制构造的对象却没有?
- sql - 检索两个字段值都存在于同一个表中的记录
- php - 如何强制 SSL WWW 到我的域和子域