DLL interface problem

David K.
Tucson, AZ

Mar 28, 2013
4 Posts

0  |  0  

Re: DLL interface problem

I am trying to interface with a DLL written in C++.  The C++ code launches a few threads that RX/TX messages.  I know the C++ works properly because I have a C++ console app that works fine.

The problem is that I time out waiting for a message.  Messages are received by a thread that waits for data to arrive.

I know that I am successfully calling into the DLL since the problem occurs in the middle of my Init function.

Does anyone know the problem?  Any suggestions on how to troublehoot the problem?

Victor B.
Lake Forest, CA

Mar 28, 2013
93 Posts

0  |  0  

Re: DLL interface problem

Hi David,

Can you post the C++ function prototype (if you have the source)?  What kind of callback is expected?  Are you passing an ATEasy procedure for the callback?

Regards,
Victor Brode

David K.
Tucson, AZ

Mar 29, 2013
4 Posts

0  |  0  

Re: DLL interface problem

Multiple threads are used to receive and process messages.  There are no callbacks.

ReadThread
- waits for data to arrive (on UDP).  Using WaitForMultipleObjects and overlapped I/O to block until data arrives
- when data is received it puts the data in a queue and sets a flag for another thread (MsgProcessorThread) to process the data

MsgProcessorThread
- waits for event to be set by ReadThread
- processes message and sets an event associated with the specific message

Main (app)
- an ATEasy test calls DLL's Initialize() function
- Initialize() correctly performs some setup (create objects, start threads)
- Initialize() sends data to device
- Initialize() waits on event (from MsgProcessorThread) indicating expected response message has been received
- Initialize() times out waiting for response message


As per a previous Magic ticket, I am using a DEF file to export my functions. The prototype of the Initialize function is:
SIM_API unsigned int __stdcall initialize(const char* pIpAddress,
                                   unsigned short encoderPort,
                                   unsigned short tonesPort)

As mentioned above, the first part of the Initialize function works fine, it is the part where I start sending and receiving messages that fails.

DrATEasy (Ron Y.)
Mission Viejo, CA

Mar 29, 2013
358 Posts

0  |  0  

Re: DLL interface problem

I suggest to post the code since it is difficult to figure it out from the above text. You may want to create a magic incident for that. Another option is to write the code in ATEasy and use the ATEasy Win Socket API from the internal library.

David K.
Tucson, AZ

Mar 29, 2013
4 Posts

0  |  0  

Re: DLL interface problem

I can't post the code and it probably wouldn't be useful since you would need the device I am trying to talk to.  I will try to boil it down to a small app that demonstrates the problem.

Are there any special considerations when dealing with multiple threads?  The documentation mentions theading models and I have tried to change those properties in my DLL project settings.  This did not work.

DrATEasy (Ron Y.)
Mission Viejo, CA

Mar 29, 2013
358 Posts

0  |  0  

Re: DLL interface problem

I suspect that one of the function requires message pump while it is waiting. Try to split the  Initialize  as follows:

- performs some setup (create objects, start threads)
- Send the data
- return to ATEasy with event handle

return to ATEasy and wait for the event using ATEasy WaitForSingleObject in ATEasy (you will need to pass the event handle back to ATEasy).

If it is not working, I think we will need a small example to show the problem.



Please Note
You need to have a M@GIC account to participate in the Forums.
Not yet registered on our website? Click here to register today!

All content, information and opinions presented on the Marvin Test Solutions User Forums are those of the authors of the posts and messages and not Marvin Test Solutions'. All attachments and files are downloaded at your own risk. [Read More]