Extern, how to import a function and rename it ?
BlitzMax Forums/BlitzMax Programming/Extern, how to import a function and rename it ?
| ||
With userlibs you could do: DesiredName():"realname" I have noticed in various mods that in bmax you can do: function Desiredname()="realname" ...but I can't get it to work. Help anyone ? |
| ||
That is only allowed within the "extern - endextern" part. the name you have within "" must be a function that can be found in the imported C ( C++, ObjC, ASM ) sourcecode. |
| ||
That is only allowed within the "extern - endextern" part. Please read my topic title. I am using the "Extern" tags, but it doesn't think the function exists. |
| ||
is the functionname within "" written right and with the right amount of parameters for input and output? ( don't know if input and output types need to be the same as well ) the 'Import "somesource.c"' (.c or what ever type of source you have ) is before extern - endextern, right? perhaps you might want to post the source of the declaration of extern and C / C++ of the function which the compiler does not like as well. |
| ||
module blah.blah Extern "win32" Function RegisterClassLALALALALALAL(lpWndClass:Byte Ptr) = "RegisterClassExA" end extern Win I try and build this module I will get the following error: Compile Error:Identifier 'RegisterClassExA' not found |
| ||
Ah you use some of the predefined things. I'm sorry in that case I think it is predefined in the Win32 compiler directive, so you can just do Function RegisterClassExA(pcWndClassEx:Byte Ptr) The '= "..."' is not needed in this case. I don't know if you can rename it somehow ... Problem is there is no description on the 'extern "OS directive"' stuff in the help, so only mark might give you a answer. |
| ||
Yeah I was already doing it without renaming. I'll wait and see what mark/skid's answer is. If they give one. |
| ||
Compile Error:Identifier 'RegisterClassExA' not found This should work. Can you post runnable code? |
| ||
This works:extern "Win32" Function RegisterClassExA(pcWndClassEx:Byte Ptr) endextern This does not work and results in the compile error above: Extern "win32" Function RegisterClassLALALALALALAL(lpWndClass:Byte Ptr) = "RegisterClassExA" end extern ( renaming the somewhere predefined RegistarClassExA from user32.dll is not possible, at least not on this way ) |
| ||
Dreamora is correct, renaming in that example does not work. |
| ||
You could keep the externs private and then make your own function that calls them with your new name. Sure, ugly, but it works. |
| ||
Well the trouble was coming when I wanted to do just that. But trouble is when it comes to seperating an api func that has the name of the blitz function already in use. In that situation it is desirable to append "api" "_" or some other token on the end of the api function call. |
| ||
Extern "win32" Function RegisterClassLALALALALALAL(lpWndClass:Byte Ptr) = "RegisterClassExA" end extern This works here - ie: no error. However, actually calling RegisterClassLALALALALALAL results in: F:/blitzmax/tmp/.bmx/untitled1.bmx.d.o(code+0x1e1): undefined reference to `RegisterClassExA' Not the error above, so not sure what's happening there. To fix the link error, you need to manually mung the symbol, ie: 'This works on my machine! Extern "win32" Function RegisterClassLALALALALALAL(lpWndClass:Byte Ptr) = "_RegisterClassExA@4" End Extern RegisterClassLALALALALALAL Null 'just testin' If you've got mingw installed (and mingw/bin in your path), you can use the 'nm' utility to look at symbols in an object or archive file, eg: cd \blitzmax\lib nm libuser32.a |
| ||
Ah, the decorated function name has to be used *learned something again ...* |
| ||
Ah that answers it X) Thanx! |
| ||
Good if to know . Thanks ! It would be good if the error used the decorated function name. |
| ||
I think it's a bug of sorts, as I Imported some ASE loader C++ code, wrote a wrapper function, then compiled it(Without error, gcc tools, using bmk) And no amount of externing let me link to it..same error as above. "TLoadASE" not defined. (But it was...clearly. With or without redefining it's name.) -Edit Just saw mark's post about the symbolising gcc does..could be that. |
| ||
I hate to say this, but it still doesn't work. Even after getting the nm output and correcting the ="_function name@paramsize" This is a bug me thinks. |
| ||
I think you will need to remove the "win32" declaration if you are declaring fully decorated names. |
| ||
not really ... at least compared to marks posting above |
| ||
What would I put instead of "win32" .. ? I have tried "", or just extern. Both give errors when trying to makemods. If I put an import "win32" and then extern (with nothing else) after, it has the same errors. If I import the individual library files using import "-luser32.a" and then a blank extern, yes thats right, same errors. [ERROR]: e:/creation/tools/blitzmax/mod/skn3.mod/win32.mod/win32.a(kernel32.bmx.o)(code+0x48): undefined reference to `_GetModuleHandleA@4' [ERROR]: e:/creation/tools/blitzmax/mod/skn3.mod/win32.mod/win32.a(kernel32.bmx.o)(code+0x5c): undefined reference to `_GetModuleHandleA@4' [ERROR]: e:/creation/tools/blitzmax/mod/skn3.mod/win32.mod/win32.a(user32.bmx.o)(code+0xda): undefined reference to `_GetClassInfoExA@12' [ERROR]: e:/creation/tools/blitzmax/mod/skn3.mod/win32.mod/win32.a(user32.bmx.o)(code+0x164): undefined reference to `_RegisterClassExA@4' [ERROR]: e:/creation/tools/blitzmax/mod/skn3.mod/win32.mod/win32.a(user32.bmx.o)(code+0x185): undefined reference to `_UnregisterClassA@8' [ERROR]: e:/creation/tools/blitzmax/mod/skn3.mod/win32.mod/win32.a(user32.bmx.o)(code+0x1dc): undefined reference to `_CreateWindowExA@48' This is really frustrating me now, and I have run out of ideas. |
| ||
did you check if this actually is really the decoration function name? This decoration might vary from compiler to compiler ( as users of visual C++ know with its cryptic decoration ;) ) |
| ||
I checked as suggested by mark using the nm commandline tool that comes with minGW |
| ||
the win32.i file says "GetModuleHandleA@4" without the _ in front of it ... perhaps different mingw / gcc versions behavior? *note: I replaced the original BM pub.win32 with birdies from the sample because it better covers the winapi* |
| ||
I was looking at the library files in the libs folder. I'll give it a try.. Your kidding me.. it actualy feckin worked !! Thank - you :D |