If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Visual C++ to Borland C++ data exchange

Hello,

I'm working on a project that involves making two dlls: one of them is in Borland C++ (file1-bc.dll), the other one is in Visual C++ (file2-vc.dll). Right now I'm prototyping and trying to make them as simple as possible and to see data being exchanged from one side to another. The working scenario is as follows: file2.dll uses LoadLibrary("file1-bc.dll") and FindProcAddress to invoke methods to obtain data from file1-bc.dll.

Came to the point of loading a set of information; using a std::list seemed like a good idea. Although both projects are compiling and linking ok, when I try to use on one side a list created on the other side; the program crashes (Access Violation).

Scenario 1
I tried instantiating the list on file2-vc.dll and passing it as an argument to be filled in the other dll: at the very first attempt of using it inside file1-bc.dll the program crashes

Scenario2
I tried instantiating the list inside file1-bc.dll and returning it to the caller: still got a crash

The list is filled with pointers to a custom defined structure (see the attached SavedUrlItem.h). So it's a std::list<SavedUrlItem*>

And here are my questions:
- can this approach work?
- if yes what would need to change (perhaps in the project settings) to make it work

Re: Visual C++ to Borland C++ data exchange

Marius,

Getting C++ to work from a DLL share is tricky at best. If I were you, I would make the entire interface between the DLL and your main App straight C. You can use C++ inside the DLL and inside the App, but communicate only by C. The reason for this is that there is no name mashing and a pointer is just a pointer. (Convert the std to a normal WCHAR array.)

Otherwise, make sure you are using shared libraries, passing a class pointer without a shared reference will not make any sense to the DLL or App.

Re: Visual C++ to Borland C++ data exchange

Originally Posted by Galois77

Hello,

I'm working on a project that involves making two dlls: one of them is in Borland C++ (file1-bc.dll), the other one is in Visual C++ (file2-vc.dll). Right now I'm prototyping and trying to make them as simple as possible and to see data being exchanged from one side to another.

No. This is not going to work.

Code:

using a std::list seemed like a good idea. Although both projects are compiling and linking ok, when I try to use on one side a list created on the other side; the program crashes (Access Violation).

Hmm... I didn't know that the Borland C++ development team and Microsoft's C++ development team spoke to each other and shared their C++ library code.

Of course I'm being sarcastic -- the point I'm making is that std::list internals are different for each compiler -- the only thing that is the same is the public interface. So basically, the two std::list's are vastly different. You cannot "share" std::list between the two compilers. Even with the different compiler versions of the same compiler, you can't use std::list between compiler versions.

The proper way to share data is to not use C++, as egawtry mentioned. The only "universal" interface between DLL and application is to use 'C', and only the basic Windows types (LONG, WPARAM, LPCSTR, BOOL, char, etc. pointers to these types, arrays of these types, etc.). Anyway, I believe in the long run this is the better approach -- what if the container is no longer std::list, but something else? Your application and your DLL would have to change to the new type. By using generic Windows types, you are not forcing the app to know what data structure is being used.

Re: Visual C++ to Borland C++ data exchange

As mentioned, the only thing std::list shared between the two languages is the interface. The pointer sent from one side to the other made no sense on the other end.

I was able to find a solution to my problem involving a variable number of elements by using a simple pattern similar to iteration over a list of found files.

bool findFirstItem(void* pItem);
bool findNextItem(void* pItem);

The address is sent from the Calling App and the dll only copies information to the supplied pointer. Inside it will keep track if there are more results and when the last result is returned, the internal list entities will be freed.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.