Thread: Calling a function from a DLL

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    204

    Calling a function from a DLL

    I've got a DLL that calls another function. The problem is that I don't know how to "glue" the function to the DLL. The DLL is

    Code:
    #include <stdio.h>
          
    extern "C" 
    {
    
       __declspec (dllexport) double __stdcall testfunc (double a)
    	{
       
          double b;	 
    	  b = triple(a);	  
    	  return b;
       }
       
    }
    and the function that I'm trying to "glue" to it is
    Code:
    double triple (double a)
    {
    	double b;
    	b = 3*a;
    
    	return b;
    }
    I've tried to just put them in the same source file but that didn't seem to work. Any help with this is appreciated.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    What do you mean by "it didn't seem to work"? Did you try putting triple() inside the extern "C" section? Not that it should make any difference if you're compiling as C, but still, it might help.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    204
    Yes.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    That's one of my questions answered . . . but what about the other one? What happens when you try this? Are you compiling as C? Are you creating a DLL? Have you ever created DLLs before?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    204
    I have created DLLs before, though I don't understand them that well. It does compiles to an object file okay, but I get the following error when linking.
    Code:
    ... :main.c:(.text+0x104): undefined reference to 'WinMain@16'
    I've tried compiling as both C and C++. I've been able to create DLLs, just not with the subroutine.

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    204
    oops, left out the -shared tag.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    DLLs don't have WinMain. You must be trying to create a win app when you should be doing a dll. What compiler/IDE? Visual Studio?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. A Function Calling a Function
    By dac in forum C++ Programming
    Replies: 8
    Last Post: 12-17-2006, 04:10 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Calling function from remote dll
    By slcjoey in forum Windows Programming
    Replies: 3
    Last Post: 09-28-2005, 08:50 AM
  5. Question on function syntax and calling function
    By cbrman in forum C Programming
    Replies: 10
    Last Post: 10-05-2003, 05:32 PM