我收到了从Delphi编译的DLL错误,该错误是在多线程中运行的c ++中使用
Delphi(Architect 10.3版本26.0.32429.4364)库代码
library Project1;
uses
System.SysUtils,
System.Classes;
{$R *.res}
procedure __test(size: integer); cdecl;
var
data : AnsiString;
begin
SetLength(data, size);
end;
exports
__test;
begin
end.
Run Code Online (Sandbox Code Playgroud)
C ++(Viausl Studio 2019)加载库并使用多线程
// ConsoleApplication1.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <Windows.h>
#include <thread>
typedef void(__cdecl *functest)(int);
HINSTANCE hInst = nullptr;
functest test;
void thread_loop() {
while (1) {
test(10);
}
}
int main()
{
hInst = LoadLibraryA("Project1.dll");
if (!hInst) {
return 0;
}
test = (functest)GetProcAddress(hInst, "__test");
if (!test) {
return 0;
}
std::thread t1(thread_loop);
std::thread t2(thread_loop);
return 1;
Run Code Online (Sandbox Code Playgroud)
我遇到了一个异常,但它不应获取任何异常,因为这是未共享的过程变量
在Delphi DLL的主块中设置IsMultiThread为True。默认情况下,Delphi的默认内存管理器假定为单线程模式。
begin
IsMultiThread := True;
end.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
134 次 |
| 最近记录: |