LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing a Pointer of struct to a DLL in LabVIEW

Highlighted

Hi,

 

I've posted some questions in another Thread, that can be seen here. However I keep having some Problems with a Project I'm working on so I'm gonna post the entire Problem here. Any help will be appreciated.

 

The Problem is as follows:

 

I have to write a program which lets me communicate with a CAN Module "tiny_CAN 2 XL". The first step would be to send out a message and display it on an oscilloscope. In order to communicate with the module I have a dll that I can use. Most of the functions work just fine when I add them to my program. Then again most of the functions require call by value integers only. The Problem is that the main function I need, which is called:

int32_t CanTransmit(uint32_t index, struct TCanMsg *msg, int32_t count);

this means I would have to pass a struct TCanMsg variable by reference, so I tried what can be seen in the first attachment.

 

None of this worked, so I tried something else. The Module came with some sample programs which I compiled. They work just fine, so I tried to model a wrapper.dll after one of the sample programs. So far, the Wrapper.dll looks like this:

 

 

// Wrapper.cpp : Definiert die exportierten Funktionen für die DLL-Anwendung.
//

#include "stdafx.h"
#include "string.h"
#include "conio.h"
#include "windows.h"
#include "C:\Users\Pete\Documents\Studienarbeit tiny_CAN\Dokumente\tiny_can\can_api\lib\can_drv.h"

extern "C" __declspec(dllexport)int PassData(unsigned int Id, unsigned char bytes[8], unsigned int Flags, unsigned int seconds, unsigned int useconds);

struct TCanMsg msg;

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{

    return TRUE;
}

int PassData(unsigned int Id, unsigned char bytes[8], unsigned int Flags, unsigned int seconds, unsigned int useconds)
{
	int ret = 1;
	msg.MsgFlags = Flags;
	msg.Id = Id;
	memcpy(msg.MsgData, bytes, 8);
	return CanTransmit(0, &msg, 1);
}

 

But when I try buliding this I get an Error:

Nicht aufgelöstes externes Symbol "_CanTransmit"

 

I don't know how exactly to translate this, but it basically means, that the program doesn't find the Function I am Calling. I cannot figure out why it can't, as I included all the same header files as in the sample program. 

 

That's about where I am stuck right now. Thank you for your input on this topic.

 

 

 



Remember Cunningham's Law
Download All
0 Kudos
Message 1 of 2
(892 Views)
Highlighted

The error states, that the IDE you are using cannot resolve a symbol called "_CanTransmit" which i assume should be defined in the can_drv.h file.

I would think that the error disappears if you rewrite the line in PassData as following:

return 0; //CanTransmit(0, &msg, 1)

 

If this is the case, the problem you are facing is a mislink or missing link to the function CanTransmit. Are you sure, that there are no further headers you have to include?

 

Norbert

 

PS: Please note that using absolute paths to modules in the code is always a bad idea....

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 2 of 2
(858 Views)