No hinstance or getProcAddress?
|
Well, using an import lib is easier, I think. Let the linker do the work. It should work with Load Library()/GetProcAddress() though. I work back and forth between PowerBASIC and C++ a lot, and if I create a dll with PowerBASIC I need to do the explicit linking because I don't have the lib file created through the compilation of the dll by the other language.
Do you want me to post a LoadLibrary()/GetProcAddress() version?
Feel free to fill me in on how to compile your code when the dll and host codes are separate projects, a few thing to be honest I don't understand there;
|
I figurred I could do it quicker with command line compiling than fighting with Visual Studio ad infinitum with 87 levels of directories created all over the place with different dozens of files scattered randomly through them. I'm a minimalist by nature.
1. I don't see any explicit pointers used, I guess passing char as an argument assumes your passing a pointer?
|
In C or C++ this...
char szBuffer[128];
...creates a memory buffer of 128 bytes. And syntactilly, this...
szBuffer
...resolves to a pointer to the base address, and is equivalent to this...
&szBuffer[0]
(address of 1st byte of buffer).
2. The outputSize value passed as 9, I guess you assumed it would be variant depending on the returned data but even so surely it should be 10 to accommodate the char end byte \0 ?
|
strncpy() is one of those funny functions that's difficult to use. I always have to read up on it to get it right, and still usually mess it up. Sometimes it appends a null byte and sometimes not - I think. But I used memset() to zero out the whole szBuffer buffer, so there was bound to be a null out there somewhere to terminate it.
3. How does Hello, World! string implicitly convert to a const char*? Is const assumed as it is an rvalue? and does the compiler assume you want to pass a pointer?
|
Not sure how to answer that. I just wanted to fill up that parameter position with something cuz I simplified the _s thing away. I'm not a very secure person and I have lots of other faults too.
But "Hello, World" is a string literal that the compiler will store in static program memory in the data segment somewhere, and stick a pointer to that in the function call. I figurred it would work.
The whole thing comes to around 90 to 100 k. I did static linking against msvcrt.dll with the /MT compiler switch. So to the best of my knowledge the binaries wouldn't ever need any redistributables to run on any x86 Windows system. I'm pretty sure I could make both thoses binaries in under 25 k total with PowerBASIC, which compiles much smaller than C++. About like bare bones C.