C_and_CPP 板


LINE

开发平台(Platform): (Ex: Win10, Linux, ...) windows 10 1803 编译器(Ex: GCC, clang, VC++...)+目标环境(跟开发平台不同的话需列出) Visual Studio 2017 社群版(15.8.3) 额外使用到的函数库(Library Used): (Ex: OpenGL, ...) 问题(Question): 小弟我主要是写delphi的,几乎没碰过c++(更之前只有稍微碰过C/VB) 今天BOSS想要把实验室中某个程式给其他老师用 因为外面根本没啥人用delphi所以叫我改写成dll给其他实验室的人呼叫 dll本身只有一个程式,没有input参数也没output参数 只读预定义的设定档和写固定的结果档 为了方便对方使用,我用delphi、C++、C#都写了一个程式码档载入dll定义好函式 让对方可以直接呼叫程式不用再自己引入dll delphi和C#都测试能正常运行,就C++问题解决不了 主要有三个问题: 1.如标题所说的VS使用debug模式下程式抓不到设定档,不过如果直接进资料夹点程式 是抓的到的 2.dll的程式执行完後测试用的主控台程式似乎就卡住了,一直没有执行到最後一行 system("pause"); 3.因为dll我编译了x86和x64版,所以在C++中用#ifdef去抓程式要载入哪个dll 但是WIN32不管是在x86还是x64下都是true,目前是编译环境在x64时用#undef WIN32 让系统只抓到 _WIN64的条件,不知道是否有更好的解法? 喂入的资料(Input):预期的正确结果(Expected Output): dll回传讯息"计算完成" 错误结果(Wrong Output): dll回传讯息"未检查到Data.csv" 程式码(Code):(请善用置底文网页, 记得排版,禁止使用图档) -----LoadDLL.h---- #pragma once #ifdef _WIN64 #undef WIN32 #endif extern void Run(); -----LoadDLL.cpp---- #include <stdio.h> #include <Windows.h> #include "LoadDLL.h" typedef void(*importFunction)(); void Run() { importFunction TempFunc; #ifdef _WIN64 HINSTANCE hinstLib = LoadLibrary(TEXT("DelphiDLL_x64.dll")); #endif // WIN64 #ifdef WIN32 HINSTANCE hinstLib = LoadLibrary(TEXT("DelphiDLL_x86.dll")); #endif // WIN32 if (hinstLib == NULL) { printf("ERROR: unable to load DLL\n"); system("pause"); } TempFunc = (importFunction)GetProcAddress(hinstLib, "Run"); if (TempFunc == NULL) { printf("ERROR: unable to find DLL function\n"); FreeLibrary(hinstLib); system("pause"); } else { TempFunc(); FreeLibrary(hinstLib); system("pause");//执行档没运行到这 } } -----main.cpp----- #include "stdafx" #include "LoadDLL.h" int main(){ Run(); system("pause"); return 0; } -------DelphiDLL--------- (此处是delphi程式语言,并且省略实际运行内容) Libary DelphiDLL; uses System.SysUtils, System.Classes, windows, vcl.dialogs, math; {$R *.res} procedure Run;stdcall; begin if FileExists('Data.csv') then begin DoSomething; ShowMessage('计算完成'); end else ShowMessage('未检查到Data.csv'); end; exports Run; end. 补充说明(Supplement): 原本在main中载入dll测试时可以正常抓到Data.csv 也会运行到最後的system("pause"); 在此先感谢各位耐心观看 --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.115.220.131
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1536685410.A.539.html ※ 编辑: commandoEX (140.115.220.131), 09/12/2018 01:04:41
1F:推 eye5002003: #elif defined(_WIN32) 就是else if啦,很多程式都用 09/12 10:48
2F:→ eye5002003: _WIN32来判断平台,所以x64一样抓的到,先抓_WIN64就解 09/12 10:50
3F:→ eye5002003: 决了。system("pause")就是用来卡住的。debug模式抓的 09/12 10:52
4F:→ eye5002003: 资料夹位置好像是专案根目录...吧 09/12 10:54
感谢大大的提点 Data.csv放在专案根目录就有抓到了没错 而加入#elif 的确能处理x64平台下同时符合_WIN64 _WIN32的问题 不过在我的认知中如果有执行到system("pause")应该会跳出一行"请按任意键继续..." 但在执行完dll後这行一直没跑出来才觉得奇怪 刚刚看了一下程式的log,最後停在 Thread Exiting: 8072 Thread Exiting: 16192 Thread Exiting: 13796 Thread Exiting: 22404 Thread Exiting: 9468 Thread Exiting: 19180 Thread Exiting: 9612 Thread Exiting: 23052 Thread Exiting: 16676 Thread Exiting: 4348 Thread Exiting: 11856 Thread Exiting: 20844 Thread Exiting: 17880 Thread Exiting: 21128 Thread Exiting: 1340 Thread Exiting: 14744 0x4748 执行绪以返回码 0 (0x0) 结束。 0x1518 执行绪以返回码 0 (0x0) 结束。 0x1178 执行绪以返回码 0 (0x0) 结束。 这个dll里面有用到delphi的平行运算函式库(Parallel Programming Library) 会是这个原因吗? ※ 编辑: commandoEX (140.115.66.73), 09/12/2018 17:00:10







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灯, 水草

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

TOP