05-14-2009 10:50 AM
I've written a DLL in MFC for use with LabView...{but I think there are probably more who can answer on this board than LabView}....
All the DLL calls are written as follows:
__declspec(dllexport) HRESULT __cdecl OpenPort ( unsigned char DeviceID )
{
return ( m_pBrickInput->OpenDevice ( DeviceID ) );
}
However, now I need to multithread the data collection, which I am trying to write like this:
static void StartRead(void)
{
CBrickApp *MyApp;
MyApp = new (CBrickApp);
MyApp->StartReader();
}
void CBrickApp::StartReader(void)
{
CWinThread *pReaderThread;
pReaderThread = AfxBeginThread (ReadThread, (void *)this, THREAD_PRIORITY_HIGHEST,
0, 0, NULL );
}
static UINT ReadThread( LPVOID pParam )
{
char bOverflow = 0x20; // space
unsigned long *inbuf;
unsigned long Words = 0; // initialized
inbuf = (unsigned long *)malloc(READBUF_SIZE_WORDS * sizeof(unsigned long));
while(Collecting)
{
Words = m_pBrickInput->ReadDecom(READBUF_SIZE_WORDS, inbuf, &bOverflow);
memcpy(buffer,inbuf, Words * sizeof(unsigned long));
}
free(inbuf);
AfxEndThread(0);
return ( S_OK );
}
--------------------------
When I try to build the DLL, I get
EBrick.obj : error LNK2001: unresolved external symbol "public: __thiscall CBrickApp::CBrickApp(void)" (??0CBrickApp@@QAE@XZ)
Debug/EBrick.dll : fatal error LNK1120: 1 unresolved externals
Any Suggestions?
DOK
05-15-2009 10:13 AM
Unresolved external symbols errors usually occur when your functions prototypes are in the header but the implementation of the function is missing. You didn't provide your full source code but it sounds as if you're missing the implementation of your constructor.
Here's a link to a MSDN forum where someone had a very similar issue. error LNK2019: unresolved external symbol
Regards,
Steven Zittrower
Applications Engineer
National Instruments
05-18-2009 12:52 PM
This code is part of a wrapper DLL. I'm wondering the following would be legal ?
This way, instead of creating a new instance of the class etc, then I can call this function from LabView as a DLL call....
__declspec(dllexport) void __cdecl StartReader(LPVOID pParam)
{
CWinThread *pReaderThread;
Collecting = TRUE;
pReaderThread = AfxBeginThread (ReadThread, pParam, THREAD_PRIORITY_HIGHEST, 0, 0, NULL );
}
...the following piece of code is for reference only
static UINT ReadThread( LPVOID pParam )
{
while(Collecting) { Words = m_pBrickInput->ReadDecom(READBUF_SIZE_WORDS, inbuf, &bOverflow); }
free(inbuf);
AfxEndThread(0);
return ( S_OK );
}
DOK
05-19-2009 05:34 PM
Hi DOK,
While technically legal, it will not solve the original problem Steven pointed out. This is no longer a LabVIEW related issue. I would recommended trying to track down a solution in another forum related to MFC and DLL writing specifically.