Solved

Memory cannot be referenced error

Posted on 2001-08-15
8
1,150 Views
Last Modified: 2012-08-14
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);
   }
}

----------





0
Comment
Question by:oohchild
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 6391355
May be problem in name of function from dll. For know exectly all name of functions I use TDump utility of Borland.  
0
 
LVL 5

Expert Comment

by:ekc
ID: 6394781
> 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?
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 6395805
O may be number/type of parameters wrong. Really need see code/description of "_my_open@12"
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:oohchild
ID: 6427350
Nothing wrong with the parameters, strange thing is it can work in debug version but crashes in release version, any idea?
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 6427636
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.
0
 
LVL 2

Expert Comment

by:udil
ID: 6445066
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.
0
 
LVL 2

Expert Comment

by:udil
ID: 6447502
I've just read the Etiquette page, and I wanted to
apologize on sending an Answer, instead of a Comment.

Udil
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 200 total points
ID: 6515108
oohchild,
Do you still need help with this?

The answer is almost certainly that you have reversed the correct order of parameters.  

Perhaps there is an old version of myopen.dll that used different parameter type or sequence.   If that copy of myopen.dll is in the Release directory, it would be called.  While the good one (in your Debug directory) would be working fine for debug builds.

-- Dan
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
returning a dereferenced pts in C++ 10 175
basic hardware to learn oop advanced design patterns 3 122
Can Live bindings change TGrid Cell Colour ? 1 61
print bytes of an integer 6 48
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question