Creating DLL

This is a discussion on Creating DLL within the Windows Programming forums, part of the Platform Specific Boards category; Hello! I'm trying to create a DLL. This is my code: Code: //just an example function... int someFunction(int i){ return ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,592
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    do you compile using C or C++?
    you can use dumpbin /exports to check what names are exported from your dll
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,592
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    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...
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    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
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  12. #12
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    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, 08: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, 04:30 AM
  4. Creating and using a Dll in Dev-C++
    By Aidman in forum C++ Programming
    Replies: 2
    Last Post: 01-17-2003, 02:07 PM
  5. Creating object of type HWND from a dll
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 03-12-2002, 11:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21