473,386 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

DLL crash due to memory corruption

6
Hi,
I have a DLL created in Borland C++, which I am trying to call at runtime using DLL LoadLibrary() from one of my Visual studio C++ project which is a DLL again. And both these are used in a .Net application.

Following is the way I am trying to export and call.

Borland C++ DLL exposing the function,

__declspec(dllexport) const char * __stdcall Function(char *paramStr1, char *paramStr2, int paramStr3)
{
// function body
// allocates memory - global variables and static variables
}
---------------
Visualt Studio C++ DLL calling the function,

HINSTANCE mHInstance;

typedef char* (__stdcall *BorlandDll) (const char*, const char*, int);
BorlandDll _BorlandDll;

_BorlandDll= (BorlandDll)::GetProcAddress(mHInstance, "Function" );

std::string returnvalue= _BorlandDll(paramStr1, paramStr2, paramStr3);


The borland Dll decodes an encoded message sent to it from VS C++ Dll by allocating memory(globaly and statically) and it makes call to another project which also allocates memory by using malloc.
When the Dll called for the first time and if the encoded message is small things are working fine, but if I try to call the Dll function over the same encoded message multiple times(max 5 times) the Dll crashes... Also if the encoded message is huge(upto 150 bytes) the Dll again crashes...

I get this following error
"Unhandled exception at 0x32554c54 in TestPerDLL.exe: 0xC0000005: Access violation reading location 0x00000012."

Remeber the borland C++ dll also calls some code which allocated huge memory.

Can somebody help me out from this. Or point me to a place where in I can refer to this kind of issues dealt before.

I also wanted to know where these memory allocation happens. In such case what is the right way of calling the DLL.
Mar 12 '08 #1
3 3097
weaknessforcats
9,208 Expert Mod 8TB
Memory for global variables is allocated when the DLL loads. However, to intialize these variables you need a DllMain(). This function is called when the dll loads and unloads (DETACH) so heap resources can be cleaned up.

I assume you can call the function using GetProcAddress(). If you can't, post again for more info.
Mar 12 '08 #2
Mant
6
The problem, was with the cross compilation. I was using both the Borland and Windows C++ compiler to build my project. I removed the dependecy for the Borland compiler by creating a Visual Studio project and it didnt crash.
But didnt understand what was the cause for the crash.
Anybody knows why???
Mar 18 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
Using two compilers should no be an issue if one compiler did the DLL and the other did the program. That is, once the bits are in place whatever compiler was used is irrelevant.

However, using two compilers to build the program or to build the dll will cause problems since the decorator (the name namgler) is not specified by the C++ standard. Each compiler is free to use its own implementation.
Mar 18 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Eric Brunel | last post by:
Hi all, I was creating a Tkinter widget in the style of the reversed tabs below Excel worksheets and I stepped in a serious problem: the code I made makes python crash with a seg fault, bus...
10
by: Alex Vinokur | last post by:
GNU g++ 3.3.3, Cygwin // Stuff static char* mbuffer = NULL; // Stuff void doit()
14
by: Jurgen Haan | last post by:
Hey all, at the company where I work we had a strange situation yesterday. Our DB2 database locked up, or as it later seemed, the DBM, or some connection manager. We couldn't open new...
14
by: JK Peck | last post by:
I have a fairly large Access application that ran correctly in Access 2000. After upgrading to Access 2003 (and recompiling and updating references), it reliably crashes at a certain point. If I...
8
by: ranjeet.gupta | last post by:
Dear All Is the Root Cause of the Memory corruption is the Memory leak, ?? suppose If in the code there is Memory leak, Do this may lead to the Memory Corruption while executing the program ? ...
1
by: tony | last post by:
hi. my NET application is using mixed c++ dll ( managed and unmanaged) in that dll , im calling api's of unamanged dll. my application crash with no exception or warning. its hard to...
110
by: alf | last post by:
Hi, is it possible that due to OS crash or mysql itself crash or some e.g. SCSI failure to lose all the data stored in the table (let's say million of 1KB rows). In other words what is the worst...
8
by: Andrew | last post by:
I am currently designing a database, using Access 2003 running on Windows Vista Premium Home. The database file format is Access 2002 / 2003 (mdb). The database is stored on a 1Gb USB memory...
1
by: Alex | last post by:
Hello everybody, I've been working for days on a "twilight zone" bug and I can't make any sense of it. This is in an application that was developped on XP and that was modified to handle Vista....
4
by: Rakesh Kumar | last post by:
Hi All - In a project of mine - I was trying to scale down the actual issue to the following piece of code. I need to allocate an array of strings and reserve the individual string to a particular...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.