Alienware Posted June 11, 2011 Report Share Posted June 11, 2011 (edited) 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 June 11, 2011 by Alienware Quote Link to comment
Aristos Queue Posted June 12, 2011 Report Share Posted June 12, 2011 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->DoSomething();} Quote Link to comment
Alienware Posted June 12, 2011 Author Report Share Posted June 12, 2011 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->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. Quote Link to comment
Aristos Queue Posted June 12, 2011 Report Share Posted June 12, 2011 Because I noticed you didn't write the function prototype, which I don't know if it was on purpose or not. Yes, that should work. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.