|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||||
|
|||||
|
Tokenizer Whitepaper Help
Here's the code I typed into a Win32 Application (not console):
Code:
HANDLE myLib = LoadLibrary("tokenizer.dll");
CompileProc Compile;
VerifyProc TestRecAlignment;
VersionProc Version;
TModuleRec tModRec;
Compile = (CompileProc)GetProcAddress(myLib, "Compile");
Version = (VersionProc)GetProcAddress(myLib, "Version");
TestRecAlignment = (VerifyProc)GetProcAddress(myLib, "TestRecAlignment");
Code:
C:\Program Files\Microsoft Visual Studio\MyProjects\RoboCode\RoboCode.cpp(14) : error C2664: 'GetProcAddress' : cannot convert parameter 1 from 'void *' to 'struct HINSTANCE__ *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
C:\Program Files\Microsoft Visual Studio\MyProjects\RoboCode\RoboCode.cpp(15) : error C2664: 'GetProcAddress' : cannot convert parameter 1 from 'void *' to 'struct HINSTANCE__ *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
C:\Program Files\Microsoft Visual Studio\MyProjects\RoboCode\RoboCode.cpp(16) : error C2664: 'GetProcAddress' : cannot convert parameter 1 from 'void *' to 'struct HINSTANCE__ *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
|
|
#2
|
||||||
|
||||||
|
Sorry, that's my fault. Instead of declaring myLib as type HANDLE, make it HINSTANCE. Sorry for the confusion.
|
|
#3
|
|||||
|
|||||
|
Quote:
|
|
#4
|
||||||
|
||||||
|
It's possible that your Console app was setup to use C, whereas your new one is set for C++. Someone correct me if I'm wrong (which I probably am), but I'm guessing that the C compiler will convert pointer data types without even asking. After all, a pointer is just a pointer until you try to dereference it...
|
|
#5
|
|||||
|
|||||
|
I'm not sure (I don't work with pointers alot), but you might be right. I don't think pointers work to well in C though (which goes along with my first statement). Is all your programs in MFC?
|
|
#6
|
||||
|
||||
|
I, too, might be wrong, but I believe C is more lax with pointers than C++. I know C++ *requires* you to type cast void pointers. (Perhaps that's why C is a better language for writing exploits?)
I never knew HANDLE was #define'd or typedef'd as a void*, which certainly adds to the confusion. |
|
#7
|
|||||
|
|||||
|
yeah
Microsoft tends to add BS additions to their windows gui to make it look hard and make themselves look original.
LPCSTR isnt that like const char* I prefer const char*, I dont know about you. |
|
#8
|
||||||
|
||||||
|
Re: yeah
Quote:
Also, using typedef in cases like this adds another layer of abstraction, which is a "good thing" from a software engineering view. Because this is translated directly into char * at compile-time, it's also one of the few abstractions that doesn't detract from performance. That said, I never touched the MS-specific ones, except when dealing with MFC/API functions, while writing either RoboGUI or RoboEmu. Both use char * and I wouldn't have it any other way. |
|
#9
|
|||
|
|||
|
rbayer is right... Microsoft uses a LOT of macros and typedefs to abstract the data types, which is a GOOD thing.
If you look at the declarations, they are usually in some sort of #ifdef condition, so that by simply adding or removing a symbol from the preprocessor, your program can use different data types without changing any code. This is very useful if you want to be able to build your project with Unicode support. |
|
#10
|
|||||
|
|||||
|
Microsoft
Still, but why use LPCTSTR, instead of like mStr, well I guess they do that for MFC. I would still rather do my own unicode support. I haven't found any good documentation with the prototypes for windows GUI and the defines such as HANDLE HINSTANCE. I've been stuck reading their header files. I like Linux GTK better, its so much more common sense to me.
I suppose that is because it takes 5-7 lines to add a toolbar to a window in GTK and 25-30+ in MSVC++ (NON MFC). |
|
#11
|
|||||
|
|||||
|
you can do something like:
#define NewName LPSTR |
|
#12
|
|||
|
|||
|
You're absolutely right in that C doesn't have much in the way of type-safety. Most of the WinAPI weird data types are #define'd void*'s or various species of int's. I use some of them and not others... just whatever fits the bill.
|
|
#13
|
|||||
|
|||||
|
The only thing I've found you can't use #define on is the comment (I wish I could though), and stuff like void, but I've not tried all of them.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Documentation / Whitepaper Ideas. | Josh Hambright | General Forum | 2 | 18-05-2003 17:15 |
| Tokenizer Confusion | Raven_Writer | Programming | 2 | 05-01-2003 16:23 |
| How to use the PBASIC tokenizer | rbayer | Programming | 0 | 12-12-2002 12:56 |
| PBASIC Tokenizer | Neal Probert | Programming | 9 | 28-10-2002 19:12 |
| Edit whitepaper | rbayer | CD Forum Support | 5 | 03-10-2002 18:11 |