更新时间:2023-02-07 18:30:55
启动的声明非常可疑:
__declspec(dllexport) HRESULT Startup(char* version);
这翻译成:
function Startup(version: PAnsiChar): HResult; stdcall; external 'myDLL.dll';
所以那里应该没有 var
.
我从您的评论中得知, cdecl
调用约定适用于您的某些代码.在这种情况下,删除 stdcall
,因为它会否决前面的 cdecl
.
I got from your comments that the cdecl
calling convention works for some of your code. In that case remove stdcall
, since it overrules the preceding cdecl
.
Open()
的声明似乎还不错(我将使用 DWORD
作为类型,而不是 Longint
,特别是因为如今,> DWORD
是 Longword
,但是在Win32中,它们的大小相同,因此对您没有太大的影响.而且您似乎也在传递正确的参数.
The declaration of Open()
seems to be pretty OK (I would use DWORD
as type, not Longint
, especially since DWORD
is Longword
these days -- but in Win32 they are the same size, so that won't make any big difference for you). And you seem to be passing the right parameters too.
您没有写回 HRESULT
值是什么.但是我认为端口 COM5
根本无法使用这些设置打开.
You did not write what the HRESULT
value is that you get back. But I assume that the port COM5
simply cannot be opened with these settings.
您应该从 Startup()
中删除 var
.
因此您可以尝试:
cdecl
代替 stdcall
(声明中的 stdcall
取代 cdecl
) HRESULT
.cdecl
instead of stdcall
(the stdcall
in your declaration overrules the cdecl
)HRESULT
that is returned.如果没有相同的硬件和软件,很可能无法从远处更好地诊断.
A better diagnosis is not possible, from a distance, without the same hardware and software, sorry.
您可以阅读我的有关转化的文章.这也有几段说明如何调试代码以找出正确的调用约定.它可能也可以帮助您解决转换标头的更多问题.
You could read my article on conversion. This has also a few paragraphs that explain how to debug the code to find out the proper calling convention. It can probably help you with more of your problems converting headers, too.