Results 1 to 2 of 2

Thread: Simple dll works with lib but not dynamic

  1. #1
    Senior Member
    Join Date
    Feb 2003

    Simple dll works with lib but not dynamic

    Im haveing an issue with a mini dll I have made. The dll contaains two functions which output the name of the current module to the DOS console. The dll works as I was able to link with the lib and use the functions contained within. So its clear the dll is not the problem.

    The problem is, when I try to use the dll dynamicaly with LoadLibrary/GetProcAddress is when I experince a error:

    Access Violation, the instruction at [XXX] referenced memory at [XXX], The memory could not be writen.

    acording to google this aparently is a buffer Overrun.

    I have used breakpoints to debug, and narrowed down the line that is causeing the problem. The call to the newly aquired function. Heres a snipplet

    ===== begin sniplet ===
    typedef void(WINAPI* PFUNC)(void);
    HINSTANCE hModule = NULL;
    PFUNC NumberList;
    hModule = LoadLibrary("mydll.dll");
    NumberList = (PFUNC) GetProcAddress(hModule, "NumberList");
    NumberList(); // Access Violation caused by this line
    ======= end sniplet ===

    As you can see the error ocures after NumberList is called and returns.

    My debuger brings me to the assembly of the problem address, but since my knowledge of asm is primitive its not much use to me.

    I have googled for this and there are many results but one stood out. Buffer Overrun. http://medialab.freaknet.org/~alpt/t...RASMAN_EXE.htm

    The exact error I am getting is discribed in the 4th paragraph.

    It is strange, as I have been able to use dlls in this maner before with no problem, the difernces in this case that I can think of is, the functions are console, whereas i had been dealing with strictly Win32.

    Im stumpted on this, perhaps someone can give me some guidence or sugestions?

  2. #2
    Senior Member
    Join Date
    Feb 2003
    Problem solved, It was a two part problem. Turns out GetProcAddress was returning NULL, not an address. So the question became why, I used GetLastError to determine "the spesified procedure could not be found". Ok so why could it not be found, well I remembered I had a tool called Dependancy Walker that lets me view dll's, http://www.dependencywalker.com/

    So I looked at the export list and low and behold, NumberList is listed at NumberList_

    ahh how did the underscore get there? Ok so I put the underscore in and solved my problem.

    all and all, flipcode has a great tutorial on Creating and using dlls in C/C++ http://www.flipcode.com/tutorials/tut_dll01.shtml

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts