Results 1 to 6 of 6

Thread: Standard DLL

  1. #1

    Thread Starter
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456

    Standard DLL

    Can someone tell me how do you make Standard DLL in VC ++. I mean what project type do you select while creating a new one to create a standard dll. What properties do you set for it. Also can we write normal c++ code inside a standard DLL. I
    mean no MFC or SDK etc..

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Yes to the second question. You can write normal C++ code, if not you couldn't write anything. The WinAPI is just an interface after all.

    As for the project, it's "Win32 DLL" in VC++6 and "Win32 Project" in VC++7. In 7 you then have to change the setting to DLL in the wizard.
    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.

  3. #3

    Thread Starter
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    Originally posted by CornedBee
    Yes to the second question. You can write normal C++ code, if not you couldn't write anything. The WinAPI is just an interface after all.

    As for the project, it's "Win32 DLL" in VC++6 and "Win32 Project" in VC++7. In 7 you then have to change the setting to DLL in the wizard.
    Can you give me some simple code to write a standard DLL.

  4. #4
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    TestDll.cpp
    Code:
    #define WIN32_LEAN_AND_MEAN //exclude sockets, etc from windows header	
    #include <windows.h> 
    #include <math.h> // for the square root function (sqrt)
    
    bool APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved )
    {
        return true; // good enough for now
    }
    
    // note that this is marked extern and _stdcall
    extern bool _stdcall Quadratic(double a, double b, double c, double *result1, double *result2)
    {
    	double tmp = (b * b) - (4 * a * c);
    	if (tmp < 0) return false;
    
    	*result1 = (-1 * b + sqrt(tmp)) / (2 * a);
    	*result2 = (-1 * b - sqrt(tmp)) / (2 * a);
    
    	return true;
    }

    TestDll.def
    Code:
    LIBRARY	TestDll
    
    EXPORTS
    	Quadratic @1
    	MyOtherFunction @2
    	AnotherFunction @3


    to call this function from Visual Basic, you would do something like this...
    VB Code:
    1. Public Declare Function Quadratic Lib "TestDll.dll" (ByVal a As _
    2.  Double, ByVal b As Double, ByVal c As Double, ByRef result1 As _
    3.  Double, ByRef result2 As Double) As Boolean
    4.  
    5. Dim result1 As Double, result2 As Double
    6. If Quadratic(1,  3, -12, result1, result2) Then
    7.      Call MessageBox(result1 & " " & result2)
    8. End If
    Last edited by sunburnt; Jan 24th, 2003 at 05:57 PM.
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    VB Boolean and C++ bool are not the same.
    VB Boolean uses 0xffffffff as true, C++ bool uses 0x00000001

    Most likely it won't matter, but it might.
    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.

  6. #6
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    CornedBee is right, I have had that problem before. It would be better to use a return type of int and check for 0 or !0.
    You would think it wouldn't matter, but inexplicably VB seems to think that this function always returns true.
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

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