Use extern "stdcall" whill change function signature on windows

image

It is expected that CommOpen turns into _CommOpen@4 when using the stdcall call conv. This is the correct mangling according to the stdcall call conv on 32bit systems. stdcall requires prepending an _ and appending an @ followed by the combined size of all arguments. I couldn't find much information about CommOpen. Do you know of any official documentation?

#include <stdbool.h>
#include <windows.h>

/*
	funciton: open serial port handle with default baudrate (9600)

	parameter:

		Port - (in)serial port name for comminication, e.g. COM1

	return: operation handle

*/
HANDLE APIENTRY CommOpen(char *Port);

/*
	funciton: open serial port handle with custom baudrate

	parameter:

		Port - (in)serial port name for comminication, e.g. COM1

		Baudrate - (in) option: 9600 / 19200 / 38400 / 57600 / 115200

	return: operation handle

*/
HANDLE APIENTRY CommOpenWithBaut(char *Port, unsigned int Baudrate);

/*
	funciton: close serial port

	parameter:

		ComHandle - (in)the operation handle opend

	return: 0 :  success, < 0 : failure

*/
int APIENTRY CommClose(HANDLE ComHandle);

/*
	funciton: send communication data

	parameter:

		ComHandle - (in)the operation handle

		TxSendLen - (in)length of send data

		TxSend - (in)send Data

		TxRcvLen - (out)length of return data

		TxRcv - (out)return data

	return: 0 :  success, < 0 : failure

*/
int APIENTRY ExecuteCommand(HANDLE ComHandle, int TxSendLen, unsigned char TxSend[], int *TxRcvLen, unsigned char TxRcv[]);

int APIENTRY CancelCommand(HANDLE ComHandle);

/*
	funciton: get the error infomation by error code

	parameter:

		FunRet - (in)error code

	return: error information

*/
char *APIENTRY GetErrMsg(int FunRet);

/*
	funciton: the switch of logging communication data

	parameter:

		Enabled - (in)whether to log or not, true: log record, false: don't log

*/
void APIENTRY LogCommData(bool Enabled);

Here is header file

I'm using libloading can be load is ok.
When I using rust raw ffi binding, compile is ok, run it exit code: 0xc0000005, STATUS_ACCESS_VIOLATION

For windows system api's extern "system" is the correct call conv. This is equivalent to stdcall on x86, so I'm not sure what the problem is. Maybe you forgot to link to the right library?

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.