|
-
Dec 29th, 2001, 06:50 PM
#1
Thread Starter
Hyperactive Member
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 {
}
-
Dec 29th, 2001, 07:36 PM
#2
Frenzied Member
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 .
-
Dec 29th, 2001, 08:02 PM
#3
Fanatic Member
Alcohol & calculus don't mix.
Never drink & derive.
-
Dec 30th, 2001, 08:02 AM
#4
Monday Morning Lunatic
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
-
Dec 30th, 2001, 08:06 AM
#5
Monday Morning Lunatic
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
-
Dec 31st, 2001, 12:25 AM
#6
Frenzied Member
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 .
-
Jan 6th, 2002, 10:45 AM
#7
parksie: why templates? I'd use overloaded functions because:
PHP Code:
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); }
What if I then write:
PHP Code:
float ar[5] = {1.2, 45.231, 46.6, 2.3e3, 0};
MessageBox(NULL, ar, ar, 0);
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.
-
Jan 6th, 2002, 11:19 AM
#8
Monday Morning Lunatic
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
-
Jan 6th, 2002, 03:37 PM
#9
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.
-
Jan 6th, 2002, 03:42 PM
#10
Monday Morning Lunatic
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
-
Jan 7th, 2002, 04:40 PM
#11
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|