954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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


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


Thank you,
Marius

Galois77
Newbie Poster
7 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

And here's the content of the SavedUrlItem.h file

struct SavedUrlItem {
	char url[2048];
	char profile[256];
	char name[128];
	char value[512];
	int indexInPage;

	char designation;
	char type;
};
Galois77
Newbie Poster
7 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

Memory allocated in a DLL must be released in the same DLL. Memory allocated in the main *.exe program must be released in the main application program. You cannot allocate memory in the DLL and release it (delete or delete[] or free() ) it in the main application program. So if the DLL populate the std::list then it must also destroy it.

Second problem: Borland and Microsoft may have very different implementations of std::list, so the two may or may not be compatible.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

Hell and thanks for the reply.

I understand the memory release issues, but I don't get that far; the program crashes when using the object passed from the other side.

Where would the std::list implementation reside? Came to the solution of using std::list so that both parts share a common ground. Wasn't aware of both sides implementing the same interface.

I forgot to add the fact that I made a successful test in using the methods only if both exe / dll were written in Borland C++

Galois77
Newbie Poster
7 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

>>Where would the std::list implementation reside?

header file. There may or may not be a *.cpp file. If there is then you will not have access to it unless you paid $$$ for the source code.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

Found out there are two different implementation of the same interface: one of them is in Visual C++, the other in Borland. One pointer created on one side has no meaning on the other end; that's why the program crashes; the approach wasn't the correct one.

My question was how could I make sure I'm accessing the same implementation; cared less about how the actual implementation.

In the end I chose a solution involving an iteration over the collection of resulting items similar to FindFile method and passing a pointer to a simple structure to dll methods.

All the best,
Marius

Galois77
Newbie Poster
7 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 
Second problem: Borland and Microsoft may have very different implementations of std::list, so the two may or may not be compatible.
Found out there are two different implementation of the same interface: one of them is in Visual C++, the other in Borland. One pointer created on one side has no meaning on the other end; that's why the program crashes; the approach wasn't the correct one.

**sigh** why did I waste my time with this.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: