Interfacing with the OS. HELP!!
BlitzMax Forums/BlitzMax Programming/Interfacing with the OS. HELP!!
| ||
Hey Guys, [Extern] works fine for functions.. but it doesnt work for flags! Extern "Win32" Function CreateFileMapping() 'works/ doesnt throw an error Global INVALID_FILE_HANDLE 'doesnt work Global PAGE_READWRITE 'doesnt work End Extern Const also fails. Any ideas why? (Edit: Research tells me i gotta perform an additional Import of the kernel32.dll, mustnt i? I also gotta declare those constants myself.. but where is a proper source to get their values from?) (Edit2: My newby implementation doesnt even work for the desired functions. It says undefined reference. But what to do different? ) |
| ||
Well, Google says INVALID_FILE_HANDLE is -1 and PAGE_READWRITE is 0x04: http://msdn.microsoft.com/en-us/library/aa366786(VS.85).aspx |
| ||
You can't put globals in an Extern block. |
| ||
Yea, got that point now.. yet i'm researching on how to include kernel32.dll, but i'm pretty sue i'll gonna make this today!^^ |
| ||
To import the kernel32 library bindings into BlitzMax apps, you should add something like:?Win32 Import "-lkernel32" ?...to the top of your source file - any functions declared in Extern blocks should then be able to be linked appropriately with the library. |
| ||
I need extended help :\ I need the following functions: CreateFileMapping() MapViewofFile() UnmapViewOfFile() They are not included in the kernel32.bmx, are they? ( At least i still get "Undefined reference" trying ?Win32 Import "-lkernel32" ? Extern "Win32" Function CreateFileMapping( hFile,lpFileMappingAttributes,flProtect,dwMaximumSizeHigh,dwMaximumSizeLow,lpName$z ) End Extern CreateFileMapping( Null,Null,Null,Null,Null,Null )) Now how would i get access to them? |
| ||
You're quite unlucky - you are nearly there. There is one added complication when dealing with Win32 API functions that accept strings as parameters. Most of the functions (apart from the very new ones that are unicode only) have two separate forms - one that expects ANSI strings and one that expects new unicode Wide Char strings. You have to choose which one you want to use, and append either 'W' or 'A' onto the end of the function name. E.g. CreateFileMappingA() or CreateFileMappingW(). If your target platform is Windows 2000 or higher, you should use the 'W' functions in favour of the 'A' equivalents as your app will be able to run better on platforms with extended character sets (e.g. Chinese, Japanese symbols). So add a 'W' onto the end of your function name, and change your last lpName$z parameter to lpName$w and it should now compile. ?Win32 Import "-lkernel32" ? Extern "Win32" Function CreateFileMappingW( hFile,lpFileMappingAttributes,flProtect,dwMaximumSizeHigh,dwMaximumSizeLow,lpName$w ) End Extern CreateFileMappingW( Null,Null,Null,Null,Null,Null ) |
| ||
I love you. I spent 8 hours failing to find this out today, thanks to you i (was) finally made it :) |
| ||
Another question.. how to get the values of all those API constants.. some seem to be ducumented, others not, some can be found on google, others not.. is there a proper source or a shell command or a "Extern const" syntax to determine? |
| ||
Ok, alright. found a WINBASE.H in my Borland\CBUILDER\INCLUDE\WIN32 .. all constants i need seem to be documented there. API Viewer 2004 also proves to be a great tool. |