Link to home
Start Free TrialLog in
Avatar of oohchild
oohchild

asked on

Memory cannot be referenced error

Hi,

I have this C++ codes that I cut and paste from a working program, but to my dismay gives me the following run time error:

The instruction at "0x0012f9de" referenced memory at "0x0000000000". The memory could not be "read".

Click on OK to terminate program
Click on Cancel to debug

Pls help.

-------------------

// Source code is as follows:

typedef WORD (*OPEN)(WORD, BYTE*, WORD*)
....

OPEN my_open
BYTE msg[256];
WORD rlen;
WORD rcode;

hDLL = LoadLibrary(_T("myopen.dll"));
if (hDLL!=NULL)
{
   my_open = (OPEN)GetProcAddress(hDLL, "_my_open@12");
   if (my_open!=NULL)
   {
     // Run time error traced to below call
     rcode = (my_open)(0, msg, &rlen);
   }
}

----------





Avatar of AlexVirochovsky
AlexVirochovsky

May be problem in name of function from dll. For know exectly all name of functions I use TDump utility of Borland.  
> May be problem in name of function from dll. For know exectly all name of functions I use TDump utility
of Borland.  

I don't think this is the problem, because the GetProcAddress() would return NULL in this case...
I suspect the problem coud be in the variable msg. You are reserving 256 bytes of the memory for it. Are you sure that your DLL function is accessing only that range of memory?
Do you have access to the myopen.dll code?
O may be number/type of parameters wrong. Really need see code/description of "_my_open@12"
Avatar of oohchild

ASKER

Nothing wrong with the parameters, strange thing is it can work in debug version but crashes in release version, any idea?
O, it is difference between Debug and Release version in VC. There are many Q in EE about this issue, but I work in BC and can't help you. Sorry.
The problem could be in the implementation of the function
in the DLL. One of the differences between Realese and
Debug, is that Debug version gives you some protection, such as "preparing" the stack with padding characters.
It could be that the function you call, is has a fault
which causes it not to run properly in a Release version.
I've just read the Etiquette page, and I wanted to
apologize on sending an Answer, instead of a Comment.

Udil
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial