Thread: Creating DLL

  1. #1
    Registered User
    Join Date
    Aug 2006
    Location
    GMT+1
    Posts
    18

    Creating DLL

    Hello!

    I'm trying to create a DLL. This is my code:
    Code:
    //just an example function...
    
    int someFunction(int i){
    	return i;
    }
    ... but here's a problem that i already run into before but never solved it. When i compile it (it actually compiles), i cannot call the function (nor from C nor any other environment - i actually need to call it from VB cause i'm developing my main app there) neither register it with the RegSvr32 application (Windows) cause it claims that this DLL doesn't have an 'Entry Point'. Since i need to call it from VB there's no problem there cause i know how to declare and call it in VB... i just don't know how to overcome this 'Entry Point' problem. What am i missing?

    Thank you!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Did you start by creating an empty DLL project, which you add to?

    All DLLs need to at least have something called DllMain() implemented.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    do you compile using C or C++?
    you can use dumpbin /exports to check what names are exported from your dll
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    Registered User
    Join Date
    Aug 2006
    Location
    GMT+1
    Posts
    18
    Quote Originally Posted by Salem
    Did you start by creating an empty DLL project, which you add to?
    Empty project.
    Quote Originally Posted by Salem
    All DLLs need to at least have something called DllMain() implemented.
    How should i go about this? Like instead of main()?
    Quote Originally Posted by vart
    do you compile using C or C++?
    C (Pelles C 4.0.5).
    Quote Originally Posted by vart
    you can use dumpbin /exports to check what names are exported from your dll
    What exactly do you mean with 'dumpbin /exports'?

    Is there an example on a simple DLL? I have searched your forums, Google... and nothing (perhaps i don't know what to search for).

  5. #5
    Registered User
    Join Date
    Aug 2006
    Location
    GMT+1
    Posts
    18
    Sorry for bumping, but, any1??

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    So does your compiler have a "create DLL project" option or not?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    You may need to export the functions, like:
    Code:
    extern "C" __declspec(dllexport) int DoStuff()
    {
       return 1337;
    }
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  8. #8
    Registered User
    Join Date
    Aug 2006
    Location
    GMT+1
    Posts
    18
    @Salem: Yes. It can create and compile DLL projects. I enter the code (the example function from post #1), compile (it compiles) and then i have this 'Entry Point' problem.

    @Magos: this doesn't work. Do i need to #include something? What do you mean by functions? Do you have a link where i can read about those functions? All i can find was sooo complicated...

  9. #9
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    have you tried to run

    dumpbin /EXPORTs <yourdllfilename>

    ?
    It will show the expoted names
    C compiler slightly modifies the function names it exports...
    you should use def file to solve this problem, or use the actual names that are exported...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  10. #10
    Registered User
    Join Date
    Aug 2006
    Location
    GMT+1
    Posts
    18
    How does that work?
    Code:
    dumpbin /EXPORTs "example.dll";
    ?? And where do i put it? Can you write an example for me?

    Thank you...

  11. #11
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    you should run it from the command prompt, if this utility is supplied with your compiler it will print the exported symbols of your dll

    If not - you can search the inet for something like "dllexplorer" that will show the required information
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  12. #12
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Have you tried /NOENTRY as a linker option in your project? I realize this option is primarily used for dll's that store only resources but it's worth a try. Essentially, it indicates that our dll will not have an entry point.

    Also, does your code resemble something like this?

    Code:
    // File: mydll.c
    // Compile: cl.exe /LD mydll.c
    
    #include <windows.h>
    
    #define DllExport __declspec(dllexport)
    
    DllExport int someFunction(int i)
    {
    	return i *2;
    }
    Code:
    // File: mydlltest.c
    // Compile cl.exe mydlltest.c
    #include <windows.h>
    #include <stdio.h>
    
    typedef int (WINAPI *myfunction)();
    myfunction someFunction;
    
    int main(void)
    {
    	HINSTANCE hLib=LoadLibrary("MyDll.dll");
    	if(hLib == NULL)
    	{
    		printf("Unable to load library!\n");
    		return - 1;
    	}
    	someFunction=(myfunction)GetProcAddress((HMODULE)hLib, "someFunction");
    	if((someFunction == NULL))
    	{
    		printf("Unable to load function\n.");
    		FreeLibrary((HMODULE)hLib);
    		return - 1;
    	}
    	printf("someFunction returned %d\n", someFunction(32));
    	FreeLibrary((HMODULE)hLib);
    	return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating a simple DLL
    By Dark_Phoenix in forum C++ Programming
    Replies: 8
    Last Post: 03-07-2009, 09:41 PM
  2. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  3. Creating DLL in DevC++
    By kkchennai in forum C Programming
    Replies: 6
    Last Post: 03-17-2006, 05:30 AM
  4. Creating and using a Dll in Dev-C++
    By Aidman in forum C++ Programming
    Replies: 2
    Last Post: 01-17-2003, 03:07 PM
  5. Creating object of type HWND from a dll
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 03-13-2002, 12:40 AM