C_and_CPP 板


LINE

最近在开发将客户提供的资源打包成供自家C#使用的DLL档, 但执行到某个函式会出现错误,错误如下, "0x00007FFE66AE1CEC (UniversalUS.dll) 中 (於 Sample.exe) 掷回例外状况: 0xC0000005: 读取位置 0x0000000000000064 时发生存取违规。" 想问问是否我的写法有误.. 范例档案如下, 客户提供的资源以3rd.h和3rd.dll表示。 Test.h档案内容如下, include "3rd.h" class __declspec(dllexport) Test { private: //define in 3rd.h 3rdTest* 3rdtest; public: Test(){ HINSTANCE hDll=LoadLibrary("3rd.dll"); typeof int(*CreateObj)(3rdTest** p3rdTest) CreateObj createObj=(CreateObj)GetProcAddress((HMODULE)hDll,"l pP createObj(&3rdtest); } ~Test() { 3retest.Release(); } int GetOtherObj(OtherObj** obj) { return 3rdtest->GetOtherObj(obj); } } ExternTest.h如下 #include "Test.h" extern "C" { extern __declspec(dllexport) Test* CreateTest(); extern __declspec(dllexport) void DisposeTest(Test* pTest); extern __declspec(dllexport) int GetOtherObj(Test* test); } Test.cpp如下 #include "ExternTest.h" extern "C" __declspec(dllexport) Test* CreateTest() { return new Test(); } extern "C" __declspec(dllexport) void DisposeTest(Test* pTest) { pTest->~Test(); } extern "C" __declspec(dllexport) OtherObj* GetOtnerObj(Test* pTest) { OtherObj* otherObj; pTest->GetOtherObj(&otherObj); return otherObj; } 在C#内使用状况如下, ShTest.cs public class ShTest:IDisposable { #region dllimport [DllImport("Test.dll")] private static extern IntPtr CreateTest(); [DllImport("Test.dll")] private static extern void DisposeTest(IntPtr pTest); [DllImport("Test.dll")] private static extern IntPtr GetOtherObj(IntPtr pTest); #endregion #region ShapeFunction IntPtr pTest; public ShTest() { pTest=CreateTest(); } public void Dispose() { DisposeTest(pTest); } public ShOtherObj GetOtherObj() { IntPtr pOtherObj=GetOtherObj(pTest); return new ShOtherObj(pOtherObj); } #endregion } 执行到IntPtr pOtherObj=GetOtherObj(pTest);时会跳出存取违规的错误讯息,请问是否 我的写法有错误呢? --
QR Code



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 185.213.82.181 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1701073753.A.439.html ※ 编辑: Dong0129 (185.213.82.181 台湾), 11/27/2023 16:30:56
1F:推 NDark: GetOtnerObj 这有TYPO吗?11/27 17:22
2F:推 NDark: 3retest.Release(); 这有TYPO吗?11/27 17:24
3F:推 NDark: return 3rdtest->GetOtherObj(obj); 这行要确认一下11/27 17:27
4F:→ NDark: 3rdtest 可能没有正确生成11/27 17:28
5F:→ NDark: 3rdtest->GetOtherObj() 呼叫下去 就看不到了11/27 17:28
6F:推 wulouise: GetProcAddr好像没写完整少括号11/27 21:53
7F:推 wulouise: OtherObj* GetOtnerObj(Test* pTest)是不是打错?11/27 22:28
有少打的括号或错字抱歉,对方回应了,要指定工作目录才行,谢谢各位帮忙! ※ 编辑: Dong0129 (185.213.82.186 台湾), 11/29/2023 11:10:19







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Gossiping站内搜寻

TOP