Kristian73

Hi to all,

I have a DLL (MyLib.DLL) writed in C++ eMbedded.

This DLL contains a function named OpenPort() an declared as follow:

__declspec (dllexport) void OpenPort()
{

// ... Any code here ...

}

Using P/Invoke I can use the function by Visual Basic code declaring the follow:

Public Declare Sub OpenPort Lib "MyLib.dll" ().

Now I've a variable in MyLib.DLL declared as follow:

__declspec (dllexport) int PortNumber;

My problem is:

haw can I use this variable in Visual Basic code

Thanx




Re: Smart Devices Native C++ Development Export an eMbedded C++ variable to Visual Basic .NET

Guang-Ming Bian - MSFT

Hi Kristian73,

Base on my understanding, you want to use a variable from dll writed in c++ embedded. If I have understood you, please let me know, thanks.

You can write a function to return or set the variable, and P/Invoke the function to get or set the variable value in Visual Basic code.

Best regards,

Guang-Ming Bian - MSFT






Re: Smart Devices Native C++ Development Export an eMbedded C++ variable to Visual Basic .NET

Kristian73

Hi, you understood well, I want use a variable (present in C++ embedded) from VB code.

My question is:

Can I access this variable directly from VB code without have to write a specific function in C++

Thanx






Re: Smart Devices Native C++ Development Export an eMbedded C++ variable to Visual Basic .NET

Ilya Tumanov

You can obtain a pointer to it (by using usual LoadLibrary()/GetProcAddress()) and access it via methods in Marshal class. That is pretty ugly though.