Thread overview | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
February 20, 2004 How to access the windows API? | ||||
---|---|---|---|---|
| ||||
I've been wondering how do you access the windows API? For example in C# i use attributes: [DllImport("user32.dll")] public static extern int MessageBoxA(int h, string m, string c, int type); and i'd calll that normally MessageBoxA(handler, "bla bla", "bla bla", null); |
February 20, 2004 Re: How to access the windows API? | ||||
---|---|---|---|---|
| ||||
Posted in reply to SpookyET | SpookyET wrote: > I've been wondering how do you access the windows API? > For example in C# i use attributes: > > [DllImport("user32.dll")] > public static extern int MessageBoxA(int h, string m, string c, int type); > > and i'd calll that normally MessageBoxA(handler, "bla bla", "bla bla", null); Here: http://www.digitalmars.com/d/windows.html and here: http://www.digitalmars.com/d/interface.html and here: http://www.digitalmars.com/d/htomodule.html Those should get you started. There's a lot of good content on www.digitalmars.com/d. Cheers, Brad |
February 20, 2004 Re: How to access the windows API? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Brad Anderson | yeah, but i don't understand how to access those C dlls like i did in C# how do i import a C dll and access it? On Fri, 20 Feb 2004 16:45:22 -0600, Brad Anderson <brad@sankaty.dot.com> wrote: > SpookyET wrote: >> I've been wondering how do you access the windows API? >> For example in C# i use attributes: >> [DllImport("user32.dll")] >> public static extern int MessageBoxA(int h, string m, string c, int type); >> and i'd calll that normally MessageBoxA(handler, "bla bla", "bla bla", null); > > Here: > http://www.digitalmars.com/d/windows.html > > and here: > http://www.digitalmars.com/d/interface.html > > and here: > http://www.digitalmars.com/d/htomodule.html > > Those should get you started. There's a lot of good content on www.digitalmars.com/d. > > Cheers, > Brad > -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ |
February 21, 2004 Re: How to access the windows API? | ||||
---|---|---|---|---|
| ||||
Posted in reply to SpookyET | SpookyET wrote:
> yeah, but i don't understand how to access those C dlls like i did in C#
>
> how do i import a C dll and access it?
Just like you do it in C or C++.
- create a import file with extern(C) instead of a header
- create an import library for a DLL using implib
- go ahead and use it! Don't forget to import your import module and to give the import library name for a linker
If you have any further questions, please search the newsgroup. They have been answered at least 20 times!
You also better see the C++ Compiler and Tools guide.
-eye
|
February 21, 2004 Re: How to access the windows API? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Minkov | Thank you, but a tutorial would be nice, it doesn't seem as easy as the .net way. On Sat, 21 Feb 2004 01:21:38 +0100, Ilya Minkov <minkov@cs.tum.edu> wrote: > SpookyET wrote: >> yeah, but i don't understand how to access those C dlls like i did in C# >> how do i import a C dll and access it? > > Just like you do it in C or C++. > > - create a import file with extern(C) instead of a header > - create an import library for a DLL using implib > - go ahead and use it! Don't forget to import your import module and to give the import library name for a linker > > If you have any further questions, please search the newsgroup. They have been answered at least 20 times! > > You also better see the C++ Compiler and Tools guide. > > -eye > -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ |
February 21, 2004 Re: How to access the windows API? | ||||
---|---|---|---|---|
| ||||
Posted in reply to SpookyET | SpookyET wrote:
> Thank you, but a tutorial would be nice, it doesn't seem as easy as the .net way.
>
If you really think about, it's actually easier in D. This code runs just fine:
import std.c.windows.windows;
void main() {
MessageBoxA(HWND_DESKTOP,"hi world","messagebox from d",MB_OK);
}
Compile it with "dmd msgbox" (or whatever you name your file).
user32.lib and kernel32.lib are automatically linked, so you don't need to
do anything special.
std.c.windows.windows contains many of the declarations you need. There's,
however, a more complete module somewhere (sorry, can't really remember).
OT, now. You can't be so close-minded (sp?) about what a programming language should be. You obviously like (or even love) C# + .NET. I honestly wander (or is it wonder?) if you have done anything with another language. If you haven't, then it explains why you're requesting all those things, and overrating C#. However if you really want to survive in the programming world, you have to understand that every language is different to the others, and if you use a language, or want to learn it, you have to learn how that particular language works and expand your mind. Now, D is not perfect: no language is. But those who are here, all of us if I'm not mistaken, think D is a good choice. Many have come saying "I want this from VB, I want this from Delphi, from Lisp, Haskell, Java...", myself included, but we all know somethings just aren't the D way.
Sorry if that didn't make much sense or wasn't explanatory enough or if you already knew that.
-----------------------
Carlos Santander Bernal
|
February 21, 2004 Re: How to access the windows API? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos Santander B. | Comment embedded. Carlos Santander B. wrote: > SpookyET wrote: > >>Thank you, but a tutorial would be nice, it doesn't seem as easy as >>the .net way. >> > > > If you really think about, it's actually easier in D. This code runs just > fine: > > import std.c.windows.windows; > void main() { > MessageBoxA(HWND_DESKTOP,"hi world","messagebox from d",MB_OK); > } > > Compile it with "dmd msgbox" (or whatever you name your file). > user32.lib and kernel32.lib are automatically linked, so you don't need to > do anything special. > std.c.windows.windows contains many of the declarations you need. There's, > however, a more complete module somewhere (sorry, can't really remember). > HERE: http://hp.vector.co.jp/authors/VA028375/d/windows.h.html > OT, now. You can't be so close-minded (sp?) about what a programming > language should be. You obviously like (or even love) C# + .NET. I honestly > wander (or is it wonder?) if you have done anything with another language. > If you haven't, then it explains why you're requesting all those things, and > overrating C#. However if you really want to survive in the programming > world, you have to understand that every language is different to the > others, and if you use a language, or want to learn it, you have to learn > how that particular language works and expand your mind. Now, D is not > perfect: no language is. But those who are here, all of us if I'm not > mistaken, think D is a good choice. Many have come saying "I want this from > VB, I want this from Delphi, from Lisp, Haskell, Java...", myself included, > but we all know somethings just aren't the D way. > > Sorry if that didn't make much sense or wasn't explanatory enough or if you > already knew that. > > ----------------------- > Carlos Santander Bernal > > |
February 21, 2004 Re: How to access the windows API? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos Santander B. | You could say that i want native C#:-) Mainly because I'm note sure if mono will succeed. D is still under development and yes I'm aware how things are done in other languages, but attributes can really do cool stuff. Wouldn't it be cool to have [DllImport] in D to save you from all that coding? I'd really love for all the D developers to stop working on individual libs and create a Delphi/.NET like library for D. Where is LoadLibrary()? dllImport("foobar.dll"): { extern(Windows): { int func(int i); int func2(int foo); } } do you have any idea how much code that would save? it is similar to the way you would do it in C# [DllImport("user32.dll")] public static extern int MessageBoxA(int h, string m, string c, int type); [DllImport("user32.dll", EntryPoint="Foobar")] public static extern int MyName(foo bar); The reason why C# is so good is becase the designers looked at dozens of languages and ways to do things and took only the good parts. It would be cool to extend attributes like that in D. If i wanted to extend that i would do public class MyDllImportAttribute : DllImportAttribute { // extend it.... } I guess i want a native/mutlti-platform .NET, mono will always be 2 years behind microsoft and can always be shut down by ms. So yeah, i'd like D to move very close to the way things are done in the .NET world and the Delphi world. Some people are doing xml work, others are doing other crap, move it all together system.xml module system.windows.forms (for gui) even though i want namespaces system.interop. On Fri, 20 Feb 2004 22:19:48 -0500, Carlos Santander B. <carlos8294@msn.com> wrote: > SpookyET wrote: >> Thank you, but a tutorial would be nice, it doesn't seem as easy as >> the .net way. >> > > If you really think about, it's actually easier in D. This code runs just > fine: > > import std.c.windows.windows; > void main() { > MessageBoxA(HWND_DESKTOP,"hi world","messagebox from d",MB_OK); > } > > Compile it with "dmd msgbox" (or whatever you name your file). > user32.lib and kernel32.lib are automatically linked, so you don't need to > do anything special. > std.c.windows.windows contains many of the declarations you need. There's, > however, a more complete module somewhere (sorry, can't really remember). > > OT, now. You can't be so close-minded (sp?) about what a programming > language should be. You obviously like (or even love) C# + .NET. I honestly > wander (or is it wonder?) if you have done anything with another language. > If you haven't, then it explains why you're requesting all those things, and > overrating C#. However if you really want to survive in the programming > world, you have to understand that every language is different to the > others, and if you use a language, or want to learn it, you have to learn > how that particular language works and expand your mind. Now, D is not > perfect: no language is. But those who are here, all of us if I'm not > mistaken, think D is a good choice. Many have come saying "I want this from > VB, I want this from Delphi, from Lisp, Haskell, Java...", myself included, > but we all know somethings just aren't the D way. > > Sorry if that didn't make much sense or wasn't explanatory enough or if you > already knew that. > > ----------------------- > Carlos Santander Bernal > > -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ |
February 21, 2004 Correction Re: How to access the windows API? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Minkov | I have to correct myself: if a DLL uses Windows calling convention (they normally should!) it should be extern(windows) instead!
-eye
Ilya Minkov wrote:
> SpookyET wrote:
>
>> yeah, but i don't understand how to access those C dlls like i did in C#
>>
>> how do i import a C dll and access it?
>
>
> Just like you do it in C or C++.
>
> - create a import file with extern(C) instead of a header
> - create an import library for a DLL using implib
> - go ahead and use it! Don't forget to import your import module and to give the import library name for a linker
>
> If you have any further questions, please search the newsgroup. They have been answered at least 20 times!
>
> You also better see the C++ Compiler and Tools guide.
>
> -eye
>
|
Copyright © 1999-2021 by the D Language Foundation