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


Thank you,
Marius

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;
};

Edited 6 Years Ago by Nick Evan: added code-tags

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.

Edited 6 Years Ago by Ancient Dragon: n/a

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++

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

<list> 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.

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

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.

This article has been dead for over six months. Start a new discussion instead.