시나리오 : 나는 C++ DLL을 가지고 있습니다. 이 DLL에서는 작업자 스레드를 만들었습니다. 작업자 스레드에서 USB 하드웨어 장치를 통한 사용자 입력을 기다리는 루프가 있습니다. USB 장치의 사용자 입력이 일부 조건을 충족하는 경우에만 루프가 끝납니다. 또한 화면에 표시하기 위해 USB 장치의 사용자 사용 피드백을 실시간으로 피드백해야합니다. 피드백을 위해 Delphi GUI를 사용하고 있습니다.작업자 스레드의 주 스레드 콜백 함수를 호출하십시오.
사용자가 USB 장치를 사용하면 Windows 시스템에서 콜백 기능이 만들어집니다. 이 콜백 함수는 동일한 C++ DLL 파일로 작성되고 USB 장치의 초기화 함수에서 매개 변수로 전달됩니다.
DLL에서 전역 변수를 플래그로 사용하여이 루프를 종료해야하는시기를 결정했습니다.
또한이 C++ DLL을 Delphi DLL에서로드 중입니다. Delphi DLL -> C++ DLL 피드백 표시는 Delphi DLL에서 가져온 것입니다.
기본적으로 지금 당면하는 문제는 ptr, funcptr 함수를 호출 할 수 없다는 것입니다. 화면에 실시간 피드백이 없습니다. 이것은 Delphi DLL의 함수입니다. 이 코드 줄은 다음과 같습니다
(*(reinterprete_cast<FUNCPTR>(funcPtr)))("this is the feedback msg displayed on Delphi GUI");
사람이에 대한 해결책을 가지고 있습니까?
저는 초보자이며 답변을 주셔서 감사합니다. 도와 주셔서 감사합니다.
//Global variable
BOOL flag = TRUE;
//A function type in Delphi calling app
typedef void (__stdcall *FUNCPTR)(PCHAR);
//Functions start here.....
DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
do {} while (flag);
}
function_1st_CalledFromDelphiDLL(FUNCPTR funcPtr)
{
Initialize_USBDevice(handleUSBDeviceEvent_callback, funcPtr);
}
function_2nd_CalledFromDelphiDLL()
{
DWORD threadID;
HANDLE hWorkerThread;
hWorkerThread = CreateThread(NULL,0,ThreadProc, 0, 0 , &threadID);
if (hWorkerThread!=NULL)
{
WaitForSingleObject(hWorkerThread, 30000);
}
}
//This is the callback function, called by Windows system when user meddles with the USB device
handleUSBDeviceEvent_callback(void *funcPtr)
{
flag = FALSE; //so loop in ThreadProc can exit
//The following code cannot be executed at all. Even when i Try MessageBox(NULL,L"msg",NULL,NULL), the message box doesn't popup too. But, I can write something to a filestream here.
(*(reinterprete_cast<FUNCPTR>(funcPtr)))("this is the feedback msg displayed on Delphi GUI");
}
코드를 추가했습니다. 사용자 입력은 USB 센서 장치입니다. – Robogal