Results 1 to 11 of 11

Thread: vc++ lib of api declarations ??

  1. #1

    Thread Starter
    Hyperactive Member Cmdr0Sunburn's Avatar
    Join Date
    May 2001
    Location
    g0t r00t?
    Posts
    461

    vc++ lib of api declarations ??

    yo, i want to create a vc++ lib of api declarations for my vb projects,

    so if i knew how to convert vb api declarations into c++ it would be helpfull

    Public Declare Sub ReleaseCapture Lib "user32" ()

    Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
    these in c++????
    I know a lot oF Vb, expert in C++, and i think in assembly.
    MSVC++6.NET
    vb6
    masm
    Windowz Xp
    I find my self using this a lot in C++

    __asm {
    }

  2. #2
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402

    Hello

    Code:
    #include <windows.h>
    After you insert the code above, the API functions will be available to use, like:

    Code:
    i = GetForeGroundWindow();
    Just a little bonus - making your own APIs:

    Code:
    extern "C" __declspec(dllexport) int _stdcall Iamanfunction(int a, LPCTSTR str);


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  3. #3
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772

    Re: Hello

    Code:
    extern "C"
    What does that do?
    Alcohol & calculus don't mix.
    Never drink & derive.

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    It forces the internal naming convention to follow C rules (like the API - the DLL mechanism in Windows only understands that).

    Otherwise, you'd end up with a C++ mangled name (which looks something like @KX_MyFunctionName@12@3fFFxxKJ).
    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

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169

    Re: Hello

    Originally posted by Microbasic
    Just a little bonus - making your own APIs:

    Code:
    extern "C" __declspec(dllexport) int _stdcall Iamanfunction(int a, LPCTSTR str);
    I just noticed. Don't use LPCTSTR - that's only for USING them.

    When you define them, if you really have to have ANSI/Unicode compatibility you need to define two functions. If you're using them in a DLL from something like VB then you'd need to have A and W versions, like Windows does.

    The C++ method, of course, is to use templates
    Code:
    	extern "C" int __stdcall MessageBoxA(HWND hWnd, const char *lpText, const char *lpCaption, UINT uType);
    	extern "C" int __stdcall MessageBoxW(HWND hWnd, const wchar_t *lpText, const wchar_t *lpCaption, UINT uType);
    	template<class chrtyp> inline int __stdcall MessageBox(HWND hWnd, const chrtyp *lpText, const chrtyp *lpCaption, UINT uType);
    	inline int __stdcall MessageBox<char>(HWND hWnd, const char *lpText, const char *lpCaption, UINT uType)
    		{ return MessageBoxA(hWnd, lpText, lpCaption, uType); }
    	inline int __stdcall MessageBox<wchar_t>(HWND hWnd, const wchar_t *lpText, const wchar_t *lpCaption, UINT uType)
    		{ return MessageBoxW(hWnd, lpText, lpCaption, uType); }
    Bonzer!
    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
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    Oh hail the great master of C++.

    OK, sorry, I usually do not worry about compatibility (most of the software that I make are programs, not DLLs) and therefore, I forgot about compatability.

    Code:
    __int64 Parksie_in_C++;
    long MicroBasic_in_C++;


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    parksie: why templates? I'd use overloaded functions because:
    PHP Code:
    template<class chrtypinline int __stdcall MessageBox(HWND hWnd, const chrtyp *lpText, const chrtyp *lpCaptionUINT uType);
        
    inline int __stdcall MessageBox<char>(HWND hWnd, const char *lpText, const char *lpCaptionUINT uType)
            { return 
    MessageBoxA(hWndlpTextlpCaptionuType); }
        
    inline int __stdcall MessageBox<wchar_t>(HWND hWnd, const wchar_t *lpText, const wchar_t *lpCaptionUINT uType)
            { return 
    MessageBoxW(hWndlpTextlpCaptionuType); } 
    What if I then write:
    PHP Code:
    float ar[5] = {1.245.23146.62.3e30};
    MessageBox(NULLarar0); 
    Not that I would do such a thing, but it is somewhat disquieting to me...

    Oh yeah, and overloads are usually easier to read and ave no disadvantage that I see.
    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.

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    If you do that it just won't compile. Note that I only provided function code for those two specialisations - nothing else.
    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

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Accepted.
    Nevertheless, why templates? Why not overloaded functions?
    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.

  10. #10
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    This is an easier way to use it, and also lets you force the resolution where necessary by using MessageBox<char>(...).

    Basically, using templates means that it fits in with anything else that's parameterised on character type.
    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

  11. #11

    Thread Starter
    Hyperactive Member Cmdr0Sunburn's Avatar
    Join Date
    May 2001
    Location
    g0t r00t?
    Posts
    461
    ill just use a vb activexdll
    I know a lot oF Vb, expert in C++, and i think in assembly.
    MSVC++6.NET
    vb6
    masm
    Windowz Xp
    I find my self using this a lot in C++

    __asm {
    }

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