www.digitalmars.com         C & C++   DMDScript  

D - How to access the windows API?

reply SpookyET <not4_u hotmail.com> writes:
I've been wondering how do you access the windows API?


[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);
Feb 20 2004
parent reply Brad Anderson <brad sankaty.dot.com> writes:
SpookyET wrote:
 I've been wondering how do you access the windows API?

 
 [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
Feb 20 2004
parent reply SpookyET <not4_u hotmail.com> writes:


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?

  [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/
Feb 20 2004
parent reply Ilya Minkov <minkov cs.tum.edu> writes:
SpookyET wrote:

 
 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
Feb 20 2004
next sibling parent reply SpookyET <not4_u hotmail.com> writes:
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:

  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/
Feb 20 2004
parent reply "Carlos Santander B." <carlos8294 msn.com> writes:
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 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 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
Feb 20 2004
next sibling parent Andrew Edwards <remove_ridimz remove_yahoo.com> writes:
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

 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

 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
 
 
Feb 20 2004
prev sibling parent SpookyET <not4_u hotmail.com> writes:

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?

[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);


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 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 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/
Feb 20 2004
prev sibling parent Ilya Minkov <minkov cs.tum.edu> writes:
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:
 


 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
Feb 21 2004