Jump to content

Problem making a C++ DLL in Visual Studio 2010 work in LabView


Recommended Posts

Hello, I've noticed that I cannot do ' extern "C" ' on the methods Open(), Close(), StartStreaming(), and StopStreaming() in the following Class:

class ApplicationIo : public FiclIo

{

friend class X5ScriptPlayer;

friend class ApplicationSettings;

typedef std::vector<__int64> IntArray;

public:

//

// Member Functions

ApplicationIo(IUserInterface * ui);

~ApplicationIo();

ModuleIo & ModIo()

{ return Module; }

unsigned int BoardCount();

void Open();

bool IsOpen()

{ return Opened; }

void Close();

void StartStreaming();

void StopStreaming();

...

}

How can I export the methods of the Class mentioned above? I've read the manuals and seen examples about how to get DLLs working in LabView, however none of them ever talk about when there is an actual Class involved and exporting the methods of said Class.

Any help would be greatly appreciated.

Edited by Alienware
Link to comment

Since "extern C" means to export a C style function, it doesn't make any sense to apply that to a function that has any parameters that are class data type. My understanding is that you can only apply "extern C" to functions that have only POD parameters. [POD = plain old data, yes, that's the actual technical term] Since all non-static member functions of a class have a "this" parameter that is of class type, that means that none of these functions can be made "extern C".

The workaround that I know about is this...

If you start with this:

class X {	public:    	int DoSomething();};

then you can do this:

extern C int DoSomethingOnX(void *xPtr) { 	X *x = (X)xPtr; 	return x-&gt;DoSomething();}

Link to comment

Since "extern C" means to export a C style function, it doesn't make any sense to apply that to a function that has any parameters that are class data type. My understanding is that you can only apply "extern C" to functions that have only POD parameters. [POD = plain old data, yes, that's the actual technical term] Since all non-static member functions of a class have a "this" parameter that is of class type, that means that none of these functions can be made "extern C".

The workaround that I know about is this...

If you start with this:

class X {	public:    	int DoSomething();};

then you can do this:

extern C int DoSomethingOnX(void *xPtr) { 	X *x = (X)xPtr; 	return x-&gt;DoSomething();}

Wow! That is very interesting!

Can I instead do:

-------------------------

extern "C" DoSomethingOnX(void* xPtr);

DoSomethingOnX(void* xPtr)

{

X *x = (X)xPtr;

return x->DoSomething();

}

Because I noticed you didn't write the function prototype, which I don't know if it was on purpose or not.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.