Results 1 to 16 of 16

Thread: Dll

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2001
    Location
    -
    Posts
    21
    Can someone be nice and explain me how to make a dll with MS Visual C++ 6 (step by step)

    I know C++, Im a newbie with vb but i know how to call funtion from a alredy make dll (like mcisendstring in winmm) so be nice and explain to me
    ---

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Firstly, you create a new project "Win32 DLL", not an MFC one. Call it "testdll" (for simplicity). Add a new blank source file called "testdll.cpp", and add the following code:
    Code:
    long __stdcall TestFunction(long lInput) {
        return lInput + 5;
    }
    Now, the only thing that's different here is the __stdcall part. This tells it which way to call the function. This calling convention is the one used by the Windows API since it's simpler to program for.

    Next, you need to add a .DEF file. This can just be a source file again, but call it "testdll.def". Add the following:
    Code:
    LIBRARY "testdll.dll"
    
    EXPORTS
        TestFunction
    This tells the linker what functions to export from the DLL for usage by other programs.

    Compile this and hopefully you should have a DLL.

    The definition for this function is:
    Code:
    Declare Function TestFunction Lib "testdll" (ByVal lInput As Long) As Long
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2001
    Location
    -
    Posts
    21
    thanks man!
    ---

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Feb 2001
    Location
    -
    Posts
    21
    the .def file where do I put it ?
    -source
    -header
    -ressource
    or it doesn't matter it juste for the form ?
    ---

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    It needs to be in the project somewhere. It doesn't really go under any of those categories so put it in the root.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Feb 2001
    Location
    -
    Posts
    21
    ok thx
    ---

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Feb 2001
    Location
    -
    Posts
    21
    ok and why when I write this :
    Code:
    double __stdcall Barre( double Now, double Max)
    	double Barre;
    	if ((Max != 0) && (Now <= Max) {
    		Barre = Now / Max;
    		return Barre;
    	}
    	else
    	{
    		return 0;
    	}
    }
    they give to me these error ?
    C:\Benoit\Informatique\WylerTeam\WTDll\WTDll.cpp(2) : warning C4518: 'double ' : storage-class or type specifier(s) unexpected here; ignored
    C:\Benoit\Informatique\WylerTeam\WTDll\WTDll.cpp(2) : error C2146: syntax error : missing ';' before identifier 'Barre'
    C:\Benoit\Informatique\WylerTeam\WTDll\WTDll.cpp(2) : fatal error C1004: unexpected end of file found

    why I can't use double ?
    ---

  8. #8
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Code:
    double __stdcall Barre( double Now, double Max)
    { <--- Try adding a brcket here, see if that helps...
    	double Barre;
    	if ((Max != 0) && (Now <= Max) {
    		Barre = Now / Max;
    		return Barre;
    	}
    	else
    	{
    		return 0;
    	}
    }
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  9. #9
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I'm getting errors when I try this:

    Code:
    #include <string>
    using namespace std;
    
    string __stdcall period(string t) {
        
    	t = t + '.';
    
    	return t;
    }
    Errors:
    Linking...
    vbshelfex.def : error LNK2001: unresolved external symbol Characters
    Debug/vbshelfex.lib : fatal error LNK1120: 1 unresolved externals
    LINK : fatal error LNK1141: failure during build of exports file
    Error executing link.exe.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  10. #10
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Nevermind. I named the function wrong in the .def file.

    But now it crashes in VB when I try to use it.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    VB doesn't understand C++ strings, which are actually a specific class.

    To pass strings back to VB, you need to go back to string buffers (or use the COM strings which I'm sure CB or someone else will pop in with)...

    http://www.parksie.net/StringDLL.zip
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  12. #12
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Yeah, the VB native string is the BSTR.

    A function that returns a string:
    Code:
    BSTR __stdcall RetString()
    {
      return SysAllocString(L"Hello, man!");
    }
    Note the L before the string! It is absolutely necessary and requires you to get familiar with the concept of UNICODE strings.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  13. #13
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Thanks...
    My evil laugh has a squeak in it.

    kristopherwilson.com

  14. #14
    Member SeaCapnJ's Avatar
    Join Date
    Jun 2003
    Location
    Wilmington, NC
    Posts
    41

    troubles

    I did the following as shown, except I named it sbuff. When I implemented this in the vb app, I could not get the value I sent to be incremented by 5. Any suggestions?


    sbuff.cpp:
    long __stdcall TestFunction(long lInput) {
    return lInput + 5;
    }


    sbuff.def:
    LIBRARY "sbuff.dll"

    EXPORTS
    TestFunction



    Declare Function TestFunction Lib "sbuff" (ByVal lInput As Long) As Long
    Last edited by SeaCapnJ; Sep 15th, 2003 at 11:30 AM.

  15. #15
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    What's your VB code?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  16. #16
    Member SeaCapnJ's Avatar
    Join Date
    Jun 2003
    Location
    Wilmington, NC
    Posts
    41

    doh

    I was just stupid. Thx cornbee.

    forgot to say i = testfunction(i)




Posting Permissions

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



Click Here to Expand Forum to Full Width