About loadlibrary problem. [modified]
-
Hello everybody ! In my dll project,I export some functions, and I used them with the static library in main project,it's normal and have none errors.dll code like this:
// Golbal variables
unsigned char ParamBuffer[0x5c];
unsigned char SendBuffer[1024];
unsigned char RecvBuffer[1024];
CWaitDlg *g_ProgressDlg;int InitParams()
{
// Initial the buffer before to write to the serialport.
// On the side,or read the buffer from some files.
}int SetSendBuffer(unsigned char *temp,int nLen)
{
memcpy(ParamBuffer,temp,nLen);
return 0;
}
int ShowDlg()
{
// Show the mode progress windows ,and how many buffer was written.
}int CreateDownThread()
{
// Here is used a new thread to write the buffer to the serialport.
...
}But I used it with dynamic library in the main project,the GUI is hang-up,and the buffer isn't written to the serialport,because I use the Portmon to catch the serial event. the main project code like this:
// this is all global variable
typedef BOOL (CALLBACK *MyTxtFormat)(char *,char *); // this function int other dll
typedef int (CALLBACK *MyShowLoadingDlg)(BOOL);
typedef int (CALLBACK *MySetSendBuffer)(unsigned char *,int nLen);
typedef int (CALLBACK *MyCreateDownThread)();
typedef int (CALLBACK *MyInitialParam)();static MyInitialParam InitialParam;
static MyShowLoadingDlg ShowLoadingDlg;
static MySetSendBuffer SetSendBuffer;
static MyCreateDownThread CreateDownThread;HINSTANCE hCode;
HINSTANCE hHardware;
MyTxtFormat TxtFormat;void CMainFrame::OnDownload()
{
TCHAR *szpBuffer = new TCHAR [8000];
unsigned char szTemp[4096];BOOL bRet = FALSE; CFile pFile; DWORD nActual = 0; memset(szpBuffer,255,8000); hCode=LoadLibrary("aaa.dll"); TxtAAA=(MyTxtFormat)GetProcAddress(hCode,"TxtFormat"); if (TxtToCode) { bRet = TxtFormat(strLDPath.GetBuffer(strLDPath.GetLength()), strBinPath.GetBuffer(strBinPath.GetLength())); if(!bRet) { MessageBox("TxtFormat error!"); return; } // In the debug window,the szpBuffer is normal. if ( pFile.Open( \_T(strBinPath),CFile::modeReadWrite | CFile::typeBinary, NULL ) ) { nActual = pFile.Read(szpBuffer, 8000); } } // This is my dll,I used F10 to debug step info, that hHardware = LoadLibrary("bbb.dll"); if(hHardware) { ShowLoadingDlg=(MyShowLoadingDlg)GetProcAddress(hHardware,"ShowLoadingDlg"); if(ShowLoadingDlg == NULL) { MessageBox("ShowLoadingDlg
-
Hello everybody ! In my dll project,I export some functions, and I used them with the static library in main project,it's normal and have none errors.dll code like this:
// Golbal variables
unsigned char ParamBuffer[0x5c];
unsigned char SendBuffer[1024];
unsigned char RecvBuffer[1024];
CWaitDlg *g_ProgressDlg;int InitParams()
{
// Initial the buffer before to write to the serialport.
// On the side,or read the buffer from some files.
}int SetSendBuffer(unsigned char *temp,int nLen)
{
memcpy(ParamBuffer,temp,nLen);
return 0;
}
int ShowDlg()
{
// Show the mode progress windows ,and how many buffer was written.
}int CreateDownThread()
{
// Here is used a new thread to write the buffer to the serialport.
...
}But I used it with dynamic library in the main project,the GUI is hang-up,and the buffer isn't written to the serialport,because I use the Portmon to catch the serial event. the main project code like this:
// this is all global variable
typedef BOOL (CALLBACK *MyTxtFormat)(char *,char *); // this function int other dll
typedef int (CALLBACK *MyShowLoadingDlg)(BOOL);
typedef int (CALLBACK *MySetSendBuffer)(unsigned char *,int nLen);
typedef int (CALLBACK *MyCreateDownThread)();
typedef int (CALLBACK *MyInitialParam)();static MyInitialParam InitialParam;
static MyShowLoadingDlg ShowLoadingDlg;
static MySetSendBuffer SetSendBuffer;
static MyCreateDownThread CreateDownThread;HINSTANCE hCode;
HINSTANCE hHardware;
MyTxtFormat TxtFormat;void CMainFrame::OnDownload()
{
TCHAR *szpBuffer = new TCHAR [8000];
unsigned char szTemp[4096];BOOL bRet = FALSE; CFile pFile; DWORD nActual = 0; memset(szpBuffer,255,8000); hCode=LoadLibrary("aaa.dll"); TxtAAA=(MyTxtFormat)GetProcAddress(hCode,"TxtFormat"); if (TxtToCode) { bRet = TxtFormat(strLDPath.GetBuffer(strLDPath.GetLength()), strBinPath.GetBuffer(strBinPath.GetLength())); if(!bRet) { MessageBox("TxtFormat error!"); return; } // In the debug window,the szpBuffer is normal. if ( pFile.Open( \_T(strBinPath),CFile::modeReadWrite | CFile::typeBinary, NULL ) ) { nActual = pFile.Read(szpBuffer, 8000); } } // This is my dll,I used F10 to debug step info, that hHardware = LoadLibrary("bbb.dll"); if(hHardware) { ShowLoadingDlg=(MyShowLoadingDlg)GetProcAddress(hHardware,"ShowLoadingDlg"); if(ShowLoadingDlg == NULL) { MessageBox("ShowLoadingDlg
-
Hello everybody ! In my dll project,I export some functions, and I used them with the static library in main project,it's normal and have none errors.dll code like this:
// Golbal variables
unsigned char ParamBuffer[0x5c];
unsigned char SendBuffer[1024];
unsigned char RecvBuffer[1024];
CWaitDlg *g_ProgressDlg;int InitParams()
{
// Initial the buffer before to write to the serialport.
// On the side,or read the buffer from some files.
}int SetSendBuffer(unsigned char *temp,int nLen)
{
memcpy(ParamBuffer,temp,nLen);
return 0;
}
int ShowDlg()
{
// Show the mode progress windows ,and how many buffer was written.
}int CreateDownThread()
{
// Here is used a new thread to write the buffer to the serialport.
...
}But I used it with dynamic library in the main project,the GUI is hang-up,and the buffer isn't written to the serialport,because I use the Portmon to catch the serial event. the main project code like this:
// this is all global variable
typedef BOOL (CALLBACK *MyTxtFormat)(char *,char *); // this function int other dll
typedef int (CALLBACK *MyShowLoadingDlg)(BOOL);
typedef int (CALLBACK *MySetSendBuffer)(unsigned char *,int nLen);
typedef int (CALLBACK *MyCreateDownThread)();
typedef int (CALLBACK *MyInitialParam)();static MyInitialParam InitialParam;
static MyShowLoadingDlg ShowLoadingDlg;
static MySetSendBuffer SetSendBuffer;
static MyCreateDownThread CreateDownThread;HINSTANCE hCode;
HINSTANCE hHardware;
MyTxtFormat TxtFormat;void CMainFrame::OnDownload()
{
TCHAR *szpBuffer = new TCHAR [8000];
unsigned char szTemp[4096];BOOL bRet = FALSE; CFile pFile; DWORD nActual = 0; memset(szpBuffer,255,8000); hCode=LoadLibrary("aaa.dll"); TxtAAA=(MyTxtFormat)GetProcAddress(hCode,"TxtFormat"); if (TxtToCode) { bRet = TxtFormat(strLDPath.GetBuffer(strLDPath.GetLength()), strBinPath.GetBuffer(strBinPath.GetLength())); if(!bRet) { MessageBox("TxtFormat error!"); return; } // In the debug window,the szpBuffer is normal. if ( pFile.Open( \_T(strBinPath),CFile::modeReadWrite | CFile::typeBinary, NULL ) ) { nActual = pFile.Read(szpBuffer, 8000); } } // This is my dll,I used F10 to debug step info, that hHardware = LoadLibrary("bbb.dll"); if(hHardware) { ShowLoadingDlg=(MyShowLoadingDlg)GetProcAddress(hHardware,"ShowLoadingDlg"); if(ShowLoadingDlg == NULL) { MessageBox("ShowLoadingDlg
You have shown the code for your main program that calls the DLL but you have not indicated where it has stopped or what the code in the DLL is doing. Try stepping into the DLL code with your debugger to see why it is hanging.
It's time for a new signature.
-
Hello everybody ! In my dll project,I export some functions, and I used them with the static library in main project,it's normal and have none errors.dll code like this:
// Golbal variables
unsigned char ParamBuffer[0x5c];
unsigned char SendBuffer[1024];
unsigned char RecvBuffer[1024];
CWaitDlg *g_ProgressDlg;int InitParams()
{
// Initial the buffer before to write to the serialport.
// On the side,or read the buffer from some files.
}int SetSendBuffer(unsigned char *temp,int nLen)
{
memcpy(ParamBuffer,temp,nLen);
return 0;
}
int ShowDlg()
{
// Show the mode progress windows ,and how many buffer was written.
}int CreateDownThread()
{
// Here is used a new thread to write the buffer to the serialport.
...
}But I used it with dynamic library in the main project,the GUI is hang-up,and the buffer isn't written to the serialport,because I use the Portmon to catch the serial event. the main project code like this:
// this is all global variable
typedef BOOL (CALLBACK *MyTxtFormat)(char *,char *); // this function int other dll
typedef int (CALLBACK *MyShowLoadingDlg)(BOOL);
typedef int (CALLBACK *MySetSendBuffer)(unsigned char *,int nLen);
typedef int (CALLBACK *MyCreateDownThread)();
typedef int (CALLBACK *MyInitialParam)();static MyInitialParam InitialParam;
static MyShowLoadingDlg ShowLoadingDlg;
static MySetSendBuffer SetSendBuffer;
static MyCreateDownThread CreateDownThread;HINSTANCE hCode;
HINSTANCE hHardware;
MyTxtFormat TxtFormat;void CMainFrame::OnDownload()
{
TCHAR *szpBuffer = new TCHAR [8000];
unsigned char szTemp[4096];BOOL bRet = FALSE; CFile pFile; DWORD nActual = 0; memset(szpBuffer,255,8000); hCode=LoadLibrary("aaa.dll"); TxtAAA=(MyTxtFormat)GetProcAddress(hCode,"TxtFormat"); if (TxtToCode) { bRet = TxtFormat(strLDPath.GetBuffer(strLDPath.GetLength()), strBinPath.GetBuffer(strBinPath.GetLength())); if(!bRet) { MessageBox("TxtFormat error!"); return; } // In the debug window,the szpBuffer is normal. if ( pFile.Open( \_T(strBinPath),CFile::modeReadWrite | CFile::typeBinary, NULL ) ) { nActual = pFile.Read(szpBuffer, 8000); } } // This is my dll,I used F10 to debug step info, that hHardware = LoadLibrary("bbb.dll"); if(hHardware) { ShowLoadingDlg=(MyShowLoadingDlg)GetProcAddress(hHardware,"ShowLoadingDlg"); if(ShowLoadingDlg == NULL) { MessageBox("ShowLoadingDlg