December 15, 2003 Re: win32 Api Calling | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lewis | Not completely general since you still have to know a priori what parameters the function takes. To do this for real you'd want to save and call thru function pointers (with correct parameters!), not use int's. I'm not sure why you have all the "auto" keywords everywhere. That's really only useful for class variables... nothing else has a 'destructor'. You shouldn't need to use auto on int's and char[]'s and such. GC already handles all that. Glad you're liking D. Now, if we can get more libraries so we don't have to code to the Win32 api directly, that'll be great. ;) Sean "Lewis" <dethbomb@hotmail.com> wrote in message news:brjjqm$1lci$3@digitaldaemon.com... > WoW... it worked!! Now i only have to link to two library's and i can call > any dll function :) I have pasted my code below for critique if someone > has any suggestions on how to make it better... I have code my first D > program without help :) as mickeyD's would say "Im Loving It!!" > > > import std.c.stdio; > > extern (Windows): int LoadLibraryA (char *lpLibFileName); > extern (Windows):int CallWindowProcA(int lpPrevWndProc,int hWnd,char* > Msg,char* wParam,int lParam); > extern (Windows): int GetProcAddress(int hModule,char *lpProcName); > extern (Windows):int GetModuleHandleA(char *lpModuleName); > > int main( char [] [] args ) { > > auto char[] Msg = "You Have Dynamically Loaded This MessageBox!!"; > auto char[] Title = "Cool Message Box Title"; > auto char[] LibraryName = "user32"; > auto char[] FunctionName = "MessageBoxA"; > auto int FunctionAddress; > auto int Success; > > try { > > FunctionAddress = DynamicLoad(LibraryName,FunctionName); > > if ( FunctionAddress != 0 ) { > Success = CallWindowProcA(FunctionAddress,0,Msg,Title,0); > } > } > catch (Object e) { > printf("%s\n",e.toString); > } > > return 0; > } > > > int DynamicLoad(char[] LibName,char[] FuncName) { > > auto int hLib; > int hProc; > > hLib = GetModuleHandleA(LibName); > > if ( hLib == 0 ) { > hLib = LoadLibraryA(LibName); > } > > if ( hLib == 0) { > return 0; > } > else { > hProc = GetProcAddress(hLib, FuncName); > } > > return hProc; > } > |
December 15, 2003 Re: win32 Api Calling | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | Sean L. Palmer wrote:
> Not completely general since you still have to know a priori what parameters
> the function takes. To do this for real you'd want to save and call thru
> function pointers (with correct parameters!), not use int's.
>
> I'm not sure why you have all the "auto" keywords everywhere. That's really
> only useful for class variables... nothing else has a 'destructor'. You
> shouldn't need to use auto on int's and char[]'s and such. GC already
> handles all that.
>
> Glad you're liking D. Now, if we can get more libraries so we don't have to
> code to the Win32 api directly, that'll be great. ;)
>
> Sean
>
Thanks for the tips! anything like that helps alot since i have alot to learn when it comes to learning how memory is managed from D, and what keywords actually do.
|
Copyright © 1999-2021 by the D Language Foundation