Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem with GetProcAddress

Problem with GetProcAddress

Scheduled Pinned Locked Moved C / C++ / MFC
help
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RedDragon2k
    wrote on last edited by
    #1

    Hey Guys, I got a piece of Unix Code but I have to make it run under Windows. Unfortunately I contains the function mmap (a Unix Function). Fortunately there is this nice DLL called cygwin1.dll which gives you some Unix Functions. HINSTANCE hDll = LoadLibrary("cygwin1.dll"); if(hDll) { printf("DLL Loaded !\r\n"); FARPROC mmap = GetProcAddress(hDll,"mmap"); if(mmap) { printf("Function found !\r\n"); mydata= mmap(mydata, myLength,PROT_READ,MAP_PRIVATE,fd,0); } else { printf("Function not found!\r\n"); } } else { printf("Failed to load DLL!\r\n"); } This is the code I use. But when I then try to call the mmap function my compiler tells me that I'm passing to many arguments to mmap. :wtf: Normally I don't load libraries at runtime. So please help me :sigh:

    E H 2 Replies Last reply
    0
    • R RedDragon2k

      Hey Guys, I got a piece of Unix Code but I have to make it run under Windows. Unfortunately I contains the function mmap (a Unix Function). Fortunately there is this nice DLL called cygwin1.dll which gives you some Unix Functions. HINSTANCE hDll = LoadLibrary("cygwin1.dll"); if(hDll) { printf("DLL Loaded !\r\n"); FARPROC mmap = GetProcAddress(hDll,"mmap"); if(mmap) { printf("Function found !\r\n"); mydata= mmap(mydata, myLength,PROT_READ,MAP_PRIVATE,fd,0); } else { printf("Function not found!\r\n"); } } else { printf("Failed to load DLL!\r\n"); } This is the code I use. But when I then try to call the mmap function my compiler tells me that I'm passing to many arguments to mmap. :wtf: Normally I don't load libraries at runtime. So please help me :sigh:

      E Offline
      E Offline
      earl
      wrote on last edited by
      #2

      Hey, You're getting a function pointer back, but GetProcAddress can't possibly know what the function definition of mmap is so you have to tell it. Assuming that you are using the results from "man mmap"

      #include < sys/mman.h >

      void* mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);

      then you would do something like this

      #include < windows.h >

      typedef void* (CALLBACK* PFNMMAP)(void*, size_t, int, int, int, off_t);

      //blah -- open the DLL, etc

      PFNMMAP pmmap;

      if( (pmmap = GetProcAddress(dllHandle, "mmap"))) {

      //do something here

      }

      now pmmap is a function pointer with the right signature -- ie of type PFNMMAP. Oh yes, modify CALLBACK based on the way the dll export table was declared (it should work for __declexport). Also, there are two types of libs on windows. One, called a .lib, is code made to be statically linked into a file. The other, for your convenience also called a .lib, is code that is statically linked at compile time but just thunks to a dll. The latter is often more convenient as it will handle the LoadLibrary and GetProcAddress stuff for you. The downside to using import libs is that windows tries to load the dll before your main / WinMain is called. If it can't find the dll you never get control. At least with manual LoadLibrary calls you can be intelligent about telling the user just what you can't find and what he or she ought to do about it. PS: I don't have a compiler on this computer so I can't promise any of this works. HTH earl

      1 Reply Last reply
      0
      • R RedDragon2k

        Hey Guys, I got a piece of Unix Code but I have to make it run under Windows. Unfortunately I contains the function mmap (a Unix Function). Fortunately there is this nice DLL called cygwin1.dll which gives you some Unix Functions. HINSTANCE hDll = LoadLibrary("cygwin1.dll"); if(hDll) { printf("DLL Loaded !\r\n"); FARPROC mmap = GetProcAddress(hDll,"mmap"); if(mmap) { printf("Function found !\r\n"); mydata= mmap(mydata, myLength,PROT_READ,MAP_PRIVATE,fd,0); } else { printf("Function not found!\r\n"); } } else { printf("Failed to load DLL!\r\n"); } This is the code I use. But when I then try to call the mmap function my compiler tells me that I'm passing to many arguments to mmap. :wtf: Normally I don't load libraries at runtime. So please help me :sigh:

        H Offline
        H Offline
        Hamid Taebi
        wrote on last edited by
        #3

        How many parameter in this function mmap and use mmap with correct parameter_**


        **_

        whitesky


        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups