Re: define new types within templates

2009-12-30 Thread Phil Deets
On Tue, 29 Dec 2009 17:44:18 -0500, teo   
wrote:



There was a way to define new types within templates and I think that I
have seen that demonstrated here in the newsgroups, but cannot find it
now. Can someone help me please?

I would like to do something like this:

template MyTemplate(T)
{
  struct T ~ "Struct"  // define FooStruct structure
  {
int x;
  }
  class T ~ "Class"  // define FooClass class
  {
void bar(T ~ "Struct" t)
{
  // ...
}
  }
}

void main()
{
  mixin MyTemplate!("Foo");
  FooStruct t;
  FooClass f = new FooClass();
  f.bar(t);
}

Hopefully I am not mistaken.


Did you try string mixins? Maybe something like this untested code:

template MyTemplate(T)
{
  mixin (CtfeReplace(q{
struct _T_Struct
{
  int x;
}
  }, "_T_", T.stringof));
  mixin (CtfeReplace(q{
class _T_Class
{
  void bar(_T_Struct t)
  {
// ...
  }
}
  }, "_T_", T.stringof));
}

Sorry if this is a duplicate post. I attempted to cancel my earlier post.


Re: Is there a reason for default-int?

2009-12-30 Thread Phil Deets
On Mon, 28 Dec 2009 16:18:46 -0500, Simen kjaeraas  
 wrote:


Apart from C legacy, is there a reason to assume anything we don't know  
what
is, is an int? Shouldn't the compiler instead say 'unknown type' or  
something

else that makes sense?



C++ abandoned default int. I think it would be best for D to do the same.

Just my 2ยข,
Phil Deets


Re: Runtime error when accessing static data in a DLL

2009-12-24 Thread Phil Deets

On Thu, 24 Dec 2009 13:10:14 -0500, Phil Deets  wrote:

On Thu, 24 Dec 2009 12:49:42 -0500, Richard Webb  
 wrote:



Sounds like you might be running into this:
http://d.puremagic.com/issues/show_bug.cgi?id=3342


Thanks for the link. That is probably my problem since I'm running  
Windows XP.


Phil


I'm quite confident now that this is the issue. I added my vote to the  
bug. Does anybody know how much the runtime uses TLS? I'm thinking about  
the possibility of adding __gshared to all its static data.


An alternative workaround would be to install Vista or 7, but although I  
do have a legal Vista install disk, I would prefer an upgrade since I  
don't want to reinstall all my programs. Also, my computer barely meets  
Vista's minimum requirements.


I also might be able to rewrite lua.exe in D and preload my code in the  
executable. Most of Lua's functionality is in a library which would not  
need to be rewritten so this might be feasible.


Re: Runtime error when accessing static data in a DLL

2009-12-24 Thread Phil Deets

On Thu, 24 Dec 2009 10:49:01 -0500, Phil Deets  wrote:


I'll work on reproducing it in a smaller scale


Reduced test case:

test.c (compiled with Visual C++ 2008 Express Edition)

// Adapted from sample code at  
http://msdn.microsoft.com/en-us/library/ms680582(VS.85).aspx

#include 
#include 

void main()
{
if(!LoadLibraryA("d.dll"))
{
LPVOID lpMsgBuf;
DWORD dw = GetLastError();
FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR) &lpMsgBuf,
0, NULL );
printf("LoadLibrary failed with error %d: %s\n", dw, lpMsgBuf);
LocalFree(lpMsgBuf);
}
}

dll.d:

import std.c.windows.windows;
int x;
extern (Windows) BOOL DllMain(HINSTANCE, ULONG, LPVOID) {
x=0;
return true;
}

dll.def:

LIBRARY "d.dll"
EXETYPE NT
SUBSYSTEM   WINDOWS
CODESHARED EXECUTE
DATAWRITE

Compiled with:

dmd dll.d dll.def -ofd.dll

When I run the C app, I get the output "LoadLibrary failed with error 998:  
Invalid access to memory location."


Re: Runtime error when accessing static data in a DLL

2009-12-24 Thread Phil Deets
On Thu, 24 Dec 2009 12:49:42 -0500, Richard Webb   
wrote:



Sounds like you might be running into this:
http://d.puremagic.com/issues/show_bug.cgi?id=3342


Thanks for the link. That is probably my problem since I'm running Windows  
XP.


Phil


Runtime error when accessing static data in a DLL

2009-12-24 Thread Phil Deets
I'm writing a DLL in D which will be loaded (not automatically, but by  
LoadLibrary) by a C application (the Lua interpreter). I'm having problems  
with globals and static data. Everything is fine if I only access stuff on  
the stack, but as soon as I access a global or a static class variable,  
either the program crashes or if I am still in DllMain, the LoadLibrary  
function will fail and GetLastError will indicate an error with the  
message "Invalid access to memory location.".


I'll work on reproducing it in a smaller scale, but does anyone know how  
to fix it?


In case it is helpful info, in DllMain under the DLL_PROCESS_ATTACH case,  
I am just calling Runtime.initialize; even though the sample calls  
gc_init, _minit, _moduleCtor, and runModuleUnitTests.


Re: Making a DLL with a static library dependency

2009-12-17 Thread Phil Deets

On Thu, 17 Dec 2009 08:32:41 -0500, Phil Deets  wrote:

On Tue, 15 Dec 2009 00:56:12 -0500, Phil Deets   
wrote:


(D 2.033) I'm porting a DLL to D. The DLL depends on a static library,  
but when I put the library name on the command-line, dmd does not  
output any DLL file. If I remove the library name from the  
command-line, dmd gives linker errors and outputs an invalid DLL. How  
do I make a DLL with a static library dependency?


(now using D 2.037) I used optlink separately from dmd to see whether  
the problem is in dmd or optlink. It turns out to be an optlink issue.  
Everything works fine when I link in phobos.lib and kernel32.lib, but as  
soon as I link in lua51.lib there is no dll output. Could this be  
because I compiled lua51.dll/.lib with Visual Studio? I'll try compiling  
Lua with dmc.


I fixed the problem by using implib on lua51.dll to generate a new .lib  
file. The DLL isn't working properly, but this is likely a different  
issue; so I'll open a new thread for that if necessary.


Re: Making a DLL with a static library dependency

2009-12-17 Thread Phil Deets

On Tue, 15 Dec 2009 00:56:12 -0500, Phil Deets  wrote:

(D 2.033) I'm porting a DLL to D. The DLL depends on a static library,  
but when I put the library name on the command-line, dmd does not output  
any DLL file. If I remove the library name from the command-line, dmd  
gives linker errors and outputs an invalid DLL. How do I make a DLL with  
a static library dependency?


(now using D 2.037) I used optlink separately from dmd to see whether the  
problem is in dmd or optlink. It turns out to be an optlink issue.  
Everything works fine when I link in phobos.lib and kernel32.lib, but as  
soon as I link in lua51.lib there is no dll output. Could this be because  
I compiled lua51.dll/.lib with Visual Studio? I'll try compiling Lua with  
dmc.


Re: Making a DLL with a static library dependency

2009-12-15 Thread Phil Deets

On Tue, 15 Dec 2009 07:06:49 -0500, Trass3r  wrote:


Phil Deets schrieb:
Actually, it depends on another DLL. The static library I need to link  
to is an import library for that DLL. I'll work on loading that DLL  
without the .lib file using the Windows API while I wait for an answer  
here.


I'm not sure if the Windows loader does such chained DLL loading.
But you can always use LoadLibrary & GetProcAddress for that purpose.


It worked fine in C++.


Re: Making a DLL with a static library dependency

2009-12-14 Thread Phil Deets

On Tue, 15 Dec 2009 00:56:12 -0500, Phil Deets  wrote:

(D 2.033) I'm porting a DLL to D. The DLL depends on a static library,  
but when I put the library name on the command-line, dmd does not output  
any DLL file. If I remove the library name from the command-line, dmd  
gives linker errors and outputs an invalid DLL. How do I make a DLL with  
a static library dependency?


Actually, it depends on another DLL. The static library I need to link to  
is an import library for that DLL. I'll work on loading that DLL without  
the .lib file using the Windows API while I wait for an answer here.


Making a DLL with a static library dependency

2009-12-14 Thread Phil Deets
(D 2.033) I'm porting a DLL to D. The DLL depends on a static library, but  
when I put the library name on the command-line, dmd does not output any  
DLL file. If I remove the library name from the command-line, dmd gives  
linker errors and outputs an invalid DLL. How do I make a DLL with a  
static library dependency?


Re: Implicit conversion from array of class to array of interface

2009-12-13 Thread Phil Deets

On Sun, 13 Dec 2009 04:08:19 -0500, Phil Deets  wrote:

I found another workaround which doesn't require a bunch of extra  
overloads. I'll probably update it to use that template someone wrote in  
that thread about static duck-typing.


I looked up this post. It was: "Re: static interface" by Simen kjaeraas at  
Thursday, November 19, 2009 6:47:08 AM.


By the way, how do I move the bool specialization into the general  
function?


void f(T)(T param)
{
static if (__traits(compiles, param[0].h()))
{
// do I[] overload here
}
else static if (T is bool) // how do I do this?
{
}
else
{
pragma(msg, "Unsupported type for f.")
static assert(0);
}
}


I figured it out; it's:

else static if (is(T == bool))

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


Re: Implicit conversion from array of class to array of interface

2009-12-13 Thread Phil Deets
On Sun, 13 Dec 2009 04:16:19 -0500, Frank Benoit  
 wrote:



casting an array of class references to an array of interface references
(or vice versa) will not work at runtime. Your program will crash.

This is because if the invisible pointer correction that is done if you
cast a single class ref to an interface ref.


C c = new C;
I i = c;

writefln( "c=%d i=%i", cast(uint)cast(void*)c, cast(uint)cast(void*)i);

This shows, the numeric values are not equal.
At the assignment were an imlicit cast is taking place, dmd inserts a
pointer adjustement. If you cast an array, nothing physically is done to
the array content. In fact you need to run a loop over the array and
cast each member on it own.


Thanks for informing me, my newer workaround avoids this problem.

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


Re: Implicit conversion from array of class to array of interface

2009-12-13 Thread Phil Deets

On Sun, 13 Dec 2009 03:22:31 -0500, Phil Deets  wrote:


(D 2.033) I have a need to do something like this code:

interface I {}
class C : I {}
class D : I {}

void f(I[]) {}
void f(bool) {}

void g(T)(T param) {
f(param);
}

int main()
{
bool b;
C[] c;
D[] d;
g(b);
g(c);
g(d);
return 0;
}

This results in the output:

temp.d(9): Error: function temp.f (I[] _param_0) is not callable using  
argument types (C[])
temp.d(9): Error: cannot implicitly convert expression (param) of type  
C[] to bool

temp.d(18): Error: template instance temp.g!(C[]) error instantiating

As you can see, I can't cast C[] to I[] when I call f because T can be  
bool too. My workaround for now is:


interface I {}
class C : I {}
class D : I {}

void f(I[]) {}
void f(C[] param) {
f(cast(I[])param);
}
void f(D[] param) {
f(cast(I[])param);
}
void f(bool) {}

void g(T)(T param) {
f(param);
}

int main()
{
bool b;
C[] c;
D[] d;
g(b);
g(c);
g(d);
return 0;
}

Is there a better way to deal with this? Is this behavior a design bug?

Phil Deets



I found another workaround which doesn't require a bunch of extra  
overloads. I'll probably update it to use that template someone wrote in  
that thread about static duck-typing.


//interface I {void h();}
class C /*: I*/ {void h() {}}
class D /*: I*/ {void h() {}}

void f(T)(T param)
{
static if (__traits(compiles, param[0].h()))
{
// do I[] overload here
}
else
{
pragma(msg, "Unsupported type for f.")
static assert(0);
}
}
void f(T:bool)(T param) {}

void g(T)(T param) {
f(param);
}

int main()
{
bool b;
C[] c;
D[] d;
g(b);
g(c);
g(d);
return 0;
}

By the way, how do I move the bool specialization into the general  
function?


void f(T)(T param)
{
static if (__traits(compiles, param[0].h()))
{
// do I[] overload here
}
else static if (T is bool) // how do I do this?
{
}
else
{
pragma(msg, "Unsupported type for f.")
static assert(0);
}
}


Implicit conversion from array of class to array of interface

2009-12-13 Thread Phil Deets

(D 2.033) I have a need to do something like this code:

interface I {}
class C : I {}
class D : I {}

void f(I[]) {}
void f(bool) {}

void g(T)(T param) {
f(param);
}

int main()
{
bool b;
C[] c;
D[] d;
g(b);
g(c);
g(d);
return 0;
}

This results in the output:

temp.d(9): Error: function temp.f (I[] _param_0) is not callable using  
argument types (C[])
temp.d(9): Error: cannot implicitly convert expression (param) of type C[]  
to bool

temp.d(18): Error: template instance temp.g!(C[]) error instantiating

As you can see, I can't cast C[] to I[] when I call f because T can be  
bool too. My workaround for now is:


interface I {}
class C : I {}
class D : I {}

void f(I[]) {}
void f(C[] param) {
f(cast(I[])param);
}
void f(D[] param) {
f(cast(I[])param);
}
void f(bool) {}

void g(T)(T param) {
f(param);
}

int main()
{
bool b;
C[] c;
D[] d;
g(b);
g(c);
g(d);
return 0;
}

Is there a better way to deal with this? Is this behavior a design bug?

Phil Deets

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


Re: Getting the text of an exception

2009-12-12 Thread Phil Deets
On Fri, 11 Dec 2009 08:32:21 -0500, Michal Minich  
 wrote:



Hello Phil,


How can I get the unadorned text of an exception?


e.msg



Thanks, is this documented somewhere?

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


Getting the text of an exception

2009-12-11 Thread Phil Deets

How can I get the unadorned text of an exception? When I run:

import std.stdio;

int main()
{
try {
throw new Exception("text");
}
catch (Exception e) {
writeln(e.toString());
}
return 0;
}

I get the output:

object.Exception: text

I could just remove the "object.Exception: ", but is this how I am  
supposed to get the text?


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


Re: Question about mutable arrays

2009-11-19 Thread Phil Deets
On Thu, 19 Nov 2009 09:16:16 -0500, A Bothe   
wrote:



Hey guys,
I've found a problem that occurred since DMD 2.034:

When I've created a dynamic array like
string[] a;

and I want to assign something via the index of this array
a[0]="Test";

DMD says the array isn't mutable...even if these are normal types like  
int or char.


Does anybody knows how to solve this problem?

Thank in advance


Does a still have length 0. You may be getting an array out of bounds  
error with a weird error message.


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


Re: Compilation constants

2009-11-12 Thread Phil Deets
On Thu, 12 Nov 2009 07:17:57 -0500, Chris Nicholson-Sauls  
 wrote:



Phil Deets wrote:

On Wed, 11 Nov 2009 13:45:17 -0500, grauzone  wrote:

You can delete your posts to emulate editing...
 I didn't know it was possible to delete posts from a newsgroup. How do  
you do that?




I don't know about any other readers, but using Thunderbird just  
right-click the message header, and there will be a "Cancel Message"  
command way down toward the bottom.


-- Chris Nicholson-Sauls


Thanks, I found a "Cancel Post" near the same place in Opera.

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


Re: Compilation constants

2009-11-11 Thread Phil Deets

On Wed, 11 Nov 2009 13:45:17 -0500, grauzone  wrote:

You can delete your posts to emulate editing...


I didn't know it was possible to delete posts from a newsgroup. How do you  
do that?


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


Re: Compilation constants

2009-11-11 Thread Phil Deets

On Wed, 11 Nov 2009 13:30:17 -0500, Phil Deets  wrote:

On Wed, 11 Nov 2009 08:50:48 -0500, bearophile  
 wrote:


In a C program I have a numeric constant SIZE (that is in [1,32]), that  
I can define when I compile the code, like this:

gcc -DSIZE=14 ...

How can I do the same thing in D? The solution I have found is to put  
in the D code:

version(B1) const SIZE = 1;
version(B2) const SIZE = 2;
version(B3) const SIZE = 3;
version(B4) const SIZE = 4;
...
version(B14) const SIZE = 14;
...

And then compile the D program with:
dmd -version=B14 ...
Or:
ldc -d-version=B14 ...

Do you know nicer ways to do this in D? (if there are no nicer ways, is  
this simple feature worth adding to D?)


Thank you, bye,
bearophile


What I would probably do is generate a simple .d file right before you  
compile.


I'm used to using forums where I can post, look at what I wrote, then edit  
if necessary. To continue my thought, the file could be called constants.d  
and it could contain just be just one line:


enum SIZE=14;


Re: Compilation constants

2009-11-11 Thread Phil Deets

On Wed, 11 Nov 2009 13:34:32 -0500, Phil Deets  wrote:

On Wed, 11 Nov 2009 13:30:17 -0500, Phil Deets   
wrote:


On Wed, 11 Nov 2009 08:50:48 -0500, bearophile  
 wrote:


In a C program I have a numeric constant SIZE (that is in [1,32]),  
that I can define when I compile the code, like this:

gcc -DSIZE=14 ...

How can I do the same thing in D? The solution I have found is to put  
in the D code:

version(B1) const SIZE = 1;
version(B2) const SIZE = 2;
version(B3) const SIZE = 3;
version(B4) const SIZE = 4;
...
version(B14) const SIZE = 14;
...

And then compile the D program with:
dmd -version=B14 ...
Or:
ldc -d-version=B14 ...

Do you know nicer ways to do this in D? (if there are no nicer ways,  
is this simple feature worth adding to D?)


Thank you, bye,
bearophile


What I would probably do is generate a simple .d file right before you  
compile.


I'm used to using forums where I can post, look at what I wrote, then  
edit if necessary. To continue my thought, the file could be called  
constants.d and it could contain just be just one line:


enum SIZE=14;


See, I need edit functionality :). s/just be just/just/


Re: Compilation constants

2009-11-11 Thread Phil Deets
On Wed, 11 Nov 2009 08:50:48 -0500, bearophile   
wrote:


In a C program I have a numeric constant SIZE (that is in [1,32]), that  
I can define when I compile the code, like this:

gcc -DSIZE=14 ...

How can I do the same thing in D? The solution I have found is to put in  
the D code:

version(B1) const SIZE = 1;
version(B2) const SIZE = 2;
version(B3) const SIZE = 3;
version(B4) const SIZE = 4;
...
version(B14) const SIZE = 14;
...

And then compile the D program with:
dmd -version=B14 ...
Or:
ldc -d-version=B14 ...

Do you know nicer ways to do this in D? (if there are no nicer ways, is  
this simple feature worth adding to D?)


Thank you, bye,
bearophile


What I would probably do is generate a simple .d file right before you  
compile.


Re: version specific enum members

2009-10-30 Thread Phil Deets
On Fri, 30 Oct 2009 06:38:44 -0500, Ary Borenszweig   
wrote:



Phil Deets wrote:
On Thu, 29 Oct 2009 18:28:12 -0500, Ary Borenszweig  
 wrote:



Ellery Newcomer wrote:

 Unfortunately, that's going to be about the best you can do, unless
you're willing to play with string mixins and their ilk.


Or unless you create an enhancement request. That seems a very valid  
one.

 Done (on the main D list).


I meant a bugzilla enhancement, otherwise it'll get lost in the  
newsgroups.


Well, I wanted to gauge support for the idea. It turns out I found a  
string mixin workaround that works; so it isn't critical for me now.


Re: version specific enum members

2009-10-29 Thread Phil Deets
On Fri, 30 Oct 2009 00:03:23 -0500, Daniel Keep  
 wrote:





Phil Deets wrote:

Hi, is there a way to add members to an enum based on conditional
compilation symbols. I tried

enum Tag {
   A, B,
   version (symbol) {
  C, D,
   }
   E,
}

but it doesn't work. I know I could do

version (symbol) {
   enum Tag { A, B, C, D, E }
} else {
   enum Tag { A, B, E }
}

but I don't want to do that since in my case, there can be quite a few
elements outside of the version, and I don't want to repeat them all.


template Version(char[] ident)
{
mixin(`version(`~ident~`) const Version = true;
   else const Version = false;`);
}

char[] genEnum(bool flag1, bool flag2)
{
return "A, B, "
 ~ (flag1 ? "C, D, " : "")
 ~ "E, F, "
 ~ (flag2 ? "G, H, " : "")
 ~ "G, ";
}

mixin(genEnum( Version!(`symbol`), Version!(`somethingElse`) ));

... is about the best you can do, I think.


Hey, thanks for the idea. I worked with it a little bit to remove the  
generator function and use multiline strings. This is what I came up with.


mixin(q"ENUM
enum Tag
{
   A, B,
ENUM"~(Version!("symbol")?q"ENUM
   C, D,
ENUM":"")~q"ENUM
   E,
}
ENUM");

That's not pretty, but it's good enough for me.


Re: version specific enum members

2009-10-29 Thread Phil Deets
On Thu, 29 Oct 2009 18:28:12 -0500, Ary Borenszweig   
wrote:



Ellery Newcomer wrote:

Phil Deets wrote:

Hi, is there a way to add members to an enum based on conditional
compilation symbols. I tried

enum Tag {
   A, B,
   version (symbol) {
  C, D,
   }
   E,
}

but it doesn't work. I know I could do

version (symbol) {
   enum Tag { A, B, C, D, E }
} else {
   enum Tag { A, B, E }
}

but I don't want to do that since in my case, there can be quite a few
elements outside of the version, and I don't want to repeat them all.



 Unfortunately, that's going to be about the best you can do, unless
you're willing to play with string mixins and their ilk.


Or unless you create an enhancement request. That seems a very valid one.


Done (on the main D list).


version specific enum members

2009-10-29 Thread Phil Deets
Hi, is there a way to add members to an enum based on conditional  
compilation symbols. I tried


enum Tag {
   A, B,
   version (symbol) {
  C, D,
   }
   E,
}

but it doesn't work. I know I could do

version (symbol) {
   enum Tag { A, B, C, D, E }
} else {
   enum Tag { A, B, E }
}

but I don't want to do that since in my case, there can be quite a few  
elements outside of the version, and I don't want to repeat them all.



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


Re: some questions about D

2009-10-23 Thread Phil Deets
On Thu, 22 Oct 2009 11:50:51 -0500, Luis P. Mendes  
 wrote:



5) Besides Alexei forthcoming book, is there documentation for the whole
language and not only to part of it as in http://compsci.ca/v3/
viewtopic.php?t=9518 and http://en.wikibooks.org/wiki/A_Beginner%
27s_Guide_to_D ?


I remember when I started trying to learn D, I had trouble here. My main  
problem was I did not think to click the "Language" link near the top of  
the D2 website to get the language documentation; so in case you  
overlooked it like I did, there is a full language documentation when you  
click Language on the top-left of  
http://www.digitalmars.com/d/2.0/index.html.


Re: amazing function behavior

2009-10-20 Thread Phil Deets
On Mon, 19 Oct 2009 02:39:57 -0500, Zarathustra  
 wrote:



Function is never called but why?
look at: window.Window.wndProc : case WM.LBUTTONDOWN
//__
module window;

private import base;
private import structs;

private static import user32;
private static import kernel32;
private static import gdi32;

private:
extern (Windows) static dword wndProc(ptr o_hwnd, dword o_msg, dword  
o_wparam, dword o_lparam){


  alias user32.EWindowMessage WM;
  auto l_wnd = cast(Window*)user32.getWindowLong(o_hwnd, 0x00);
 if(o_msg == WM.NCCREATE){
user32.setWindowLong(o_hwnd, 0x00, *(cast(dword*)o_lparam));
  }
  else if(l_wnd is null){
return 0x00;
  }
 return (cast(Window*)user32.getWindowLong(o_hwnd,  
0x00)).wndProc(o_hwnd, o_msg, o_wparam, o_lparam);

}

public:
class Window{
  private const ptr handle;

  void onMouseDown(MouseEventArgs o_mea){
user32.messageBox(null, cast(wstr)"Window", cast(wstr)"msg", 0x00);
  }

  this(){
WINWndClassEx wndClass;

wndClass.size  = 0x0030;
wndClass.style = 0x0003;
wndClass.wndProc   = cast(ptr)&.wndProc;
wndClass.clsExtraBytes = 0x;
wndClass.wndExtraBytes = 0x0004;
wndClass.hInstance = kernel32.getModuleHandle(null);
wndClass.hIcon = user32.loadIcon(null, 0x7F00);
wndClass.hCursor   = user32.loadCursor(null, 0x7F00);
wndClass.hbrBackground = gdi32.getStockObject(0x);
wndClass.menuName  = null;
wndClass.className = cast(wstr)"clsname";
wndClass.hIconSm   = user32.loadIcon(null, 0x7F00);
   if(!user32.registerClassEx(cast(ptr)&wndClass)){
  if(kernel32.getLastError() != 0x0582){
user32.messageBox(null,  
user32.translateErrorCode(kernel32.getLastError()), cast(wstr)"error",  
0x);

assert(false, "window class registering failed");
  }
}

handle = user32.createWindowEx(
  0,
  wndClass.className,
  cast(wstr)"",
  0x00CF,
  0x,
  0x,
  0x0280,
  0x01E0,
  null,
  null,
  kernel32.getModuleHandle(null),
  cast(ptr)&this
);
   if(handle is null){
  user32.messageBox(null,  
user32.translateErrorCode(kernel32.getLastError()), cast(wstr)"error",  
0x);

  assert(false, "window creating failed");
}
  }

  public void run(){
WINMsg msg;
   user32.showWindow(handle, 0x000A);
user32.updateWindow(handle);

while(user32.getMessage(cast(ptr)&msg, null, 0, 0)){
  user32.translateMessage(cast(ptr)&msg);
  user32.dispatchMessage(cast(ptr)&msg);
}
  }

  private dword wndProc(ptr o_hwnd, dword o_msg, dword o_wparam, dword  
o_lparam){


alias user32.EWindowMessage WM;
alias user32.EMouseKey  WK;

switch(o_msg){

  case WM.DESTROY:
user32.postQuitMessage(0x00);
  break;

  case WM.LBUTTONDOWN:
MouseEventArgs l_mea;
l_mea.button = MouseButton.LEFT;
l_mea.location.x = loword(o_lparam);
l_mea.location.x = hiword(o_lparam);
user32.messageBox(null, cast(wstr)"LBUTTONDOWN",  
cast(wstr)"msg", 0x00); // ok it is displayed
this.onMouseDown(l_mea);  
// !!! it is never called

  break;
 default: return user32.defWindowProc(o_hwnd, o_msg, o_wparam,  
o_lparam);

}
return 0;
  }

  public Rect getBounds(){
WINRect l_rc;
user32.getWindowRect(this.handle, cast(ptr)&l_rc);
   with(l_rc) return Rect(left, top, right - left, bottom - top);
  }
}
//



I don't know what the problem is, but I would try checking to see if the  
pointer at window construction and the this pointer before calling  
onMouseDown are the same. Maybe there is a problem with using the result  
of getWindowLong as a pointer. For example, one value could be 32-bits and  
the pointer could be 64-bits. I didn't run the code to test anything, I'm  
just throwing out some ideas which may be way off.


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


Re: looking for an IDE

2009-09-30 Thread Phil Deets

On Wed, 30 Sep 2009 15:49:33 -0500, Phil Deets  wrote:


On Wed, 30 Sep 2009 09:01:04 -0500, Trass3r  wrote:


Phil Deets schrieb:
I tried Descent, but it didn't work well at all with my D2 program. It  
also didn't support building. I'll look into Poseidon. Thanks.




D2 support isn't that good in Descent yet.
Building is supported by using the external tools feature, though you  
should really use xfBuild, dsss totally fails for me when it comes to  
D2.


I had never heard of xfBuild. I'll look into it. It looks good based on  
a brief look at their website.




Wow, my first impressions of using xfBuild aren't good. I gave my thoughts  
and my cmd session below. First, I couldn't find any documentation so I  
tried a -? switch.


====
C:\Documents and Settings\Phil Deets\My Documents\Tech\Projects\D\D  
Test>xfbuild

 -?
object.Exception: At least one MODULE needs to be specified, see +help

[  429045]   0+0   tango.core.stacktrace.WinStackTrace.winAddrBacktrace
@0+87413 :0
[  424c39]   0+0
tango.core.stacktrace.StackTrace.defaultAddrBacktrace

@0+69993 :0
[  406c9d]   0+0
xf.utils.Profiler.__T7profileVG4aa4_6d61696eZ.profile!(vo

id).profile @0+9 ..\utils\Profiler.d:121
[  4022aa]   0+0   __Dmain
@0+9 Main.d:107
[  42ba67]   0+0   _main
@0+98199 :0
[  4374e0]   0+0   _mainCRTStartup
@0+145936 :0
[7c817074]   0+0   ???
   @0+2084582820 :0


Seems strange that caused an exceptions, but OK, so it mentions +help.  
I'll try that.


====
C:\Documents and Settings\Phil Deets\My Documents\Tech\Projects\D\D  
Test>xfbuild

 +help
tango.core.Exception.IOException: .deps :: The volume for a file has been  
extern

ally altered so that the opened file is no longer valid.

[  429045]   0+0   tango.core.stacktrace.WinStackTrace.winAddrBacktrace
@0+87413 :0
[  424c39]   0+0
tango.core.stacktrace.StackTrace.defaultAddrBacktrace

@0+69993 :0
[  40cdb0]   0+0   xfbuild.BuildTask.BuildTask._ctor
@0+5 BuildTask.d:44
[  40dbbd]   0+0
xf.utils.Profiler.__T7profileVG18aa18_4275696c645461736b2

e7265616444657073Z.profile!(void).profile @0+9 ..\utils\Profiler.d:121
[  40cd94]   0+0   xfbuild.BuildTask.BuildTask._ctor
@0+10 BuildTask.d:43
[  402c24]   0+0   xfbuild.Main.main.__dgliteral1
@0+35 Main.d:262
[  406c9d]   0+0
xf.utils.Profiler.__T7profileVG4aa4_6d61696eZ.profile!(vo

id).profile @0+9 ..\utils\Profiler.d:121
[  4022aa]   0+0   __Dmain
@0+9 Main.d:107
[  42ba67]   0+0   _main
@0+98199 :0
[  4374e0]   0+0   _mainCRTStartup
@0+145936 :0
[7c817074]   0+0   ???
   @0+2084582820 :0


Another exception. Maybe I should just not use a switch.


C:\Documents and Settings\Phil Deets\My Documents\Tech\Projects\D\D  
Test>xfbuild


xfBuild 0.4 :: Copyright (C) 2009 Team0xf

Usage:
xfbuild [--help]
xfbuild [ROOT | OPTION | COMPILER OPTION]...

Track dependencies and their changes of one or more modules,  
compile the

m
with COMPILER OPTION(s) and link all objects into OUTPUT [see  
OPTION(s)]

.

ROOT:
String ended with either ".d" or "/" indicating a module
or a directory of modules to be compiled, respectively.

OPTION(s) are prefixed by "+".
COMPILER OPTION(s) are anything that is not OPTION(s) or ROOT(s).

Recognized OPTION(s):
+xPACKAGEDon't compile any modules within the package
+fullPerform a full build
+clean   Remove object files
+redep   Remove the dependency file
+v   Print the compilation commands
+h   Manage headers for faster compilation
+profile Dump profiling info at the end
+modLimitNUM Compile max NUM modules at a time
+DDEPS   Put the resulting dependencies into DEPS [default:  
.deps]

+OOBJS   Put compiled objects into OBJS [default: .objs]
+q   Use -oq when compiling (only supported by ldc)
+noopDon't use -op when compiling
+nolink  Don't link
+oOUTPUT Link objects into the resulting binary OUTPUT
+cCOMPILER   Use the D Compiler COMPILER [default: dmd]
+rmo Reverse Module Order (when compiling - might uncrash  
OPTLIN

K)

Environment Variables:
XFBUILDFLAGS You can put any option from above into that variable
   Note: Keep in mind that command line options  
overrid

Re: looking for an IDE

2009-09-30 Thread Phil Deets
On Wed, 30 Sep 2009 09:05:37 -0500, A Bothe   
wrote:



Hi, I think I've got what you want...

http://www.alexanderbothe.com/?id=27 - the D-IDE


I tried that. It has potential, but here is a list of problems I had:

* Unpinned panels don't collapse until you unpin a second panel.
* When I right-clicked a project and click add folder, I got an unhandled  
exception message:


System.InvalidOperationException: BeginEdit did not succeed because  
LabelEdit property is false.

   at System.Windows.Forms.TreeNode.BeginEdit()
   at  
D_IDE.ProjectExplorer.createNewDirectoryToolStripMenuItem_Click(Object  
sender, EventArgs e)
   at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs  
e)

   at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
   at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e,  
ToolStripItemEventType met)
   at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e,  
ToolStripItemEventType met)

   at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons  
button, Int32 clicks)

   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ToolStrip.WndProc(Message& m)
   at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&  
m)

   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,  
IntPtr wparam, IntPtr lparam)


* After trying repeatedly to get a context menu on this new folder that  
didn't properly get added, it would not come up. Then suddenly, the folder  
disappeared and another file mysteriously opened.
* After adding a folder again and getting the same error, then repeatedly  
right clicking on the folder again, and right clicking on other items in  
Project Files, I got a message box that asked if I really wanted to create  
a new project. This was very strange as I didn't left click anywhere to  
make this happen. I was just right-clicking stuff outside of context menus.


After this, I quit out of fear the program was corrupted in memory and it  
might go wacky and mess up my files.


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


Re: looking for an IDE

2009-09-30 Thread Phil Deets

On Wed, 30 Sep 2009 09:01:04 -0500, Trass3r  wrote:


Phil Deets schrieb:
I tried Descent, but it didn't work well at all with my D2 program. It  
also didn't support building. I'll look into Poseidon. Thanks.




D2 support isn't that good in Descent yet.
Building is supported by using the external tools feature, though you  
should really use xfBuild, dsss totally fails for me when it comes to D2.


I had never heard of xfBuild. I'll look into it. It looks good based on a  
brief look at their website.


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


Re: looking for an IDE

2009-09-30 Thread Phil Deets

On Wed, 30 Sep 2009 02:46:12 -0500, Saaa  wrote:



Phil Deets wrote

I tried Descent, but it didn't work well at all with my D2 program. It
also didn't support building. I'll look into Poseidon. Thanks.


What exactly do you expect from supporting building?
I use descent to build my project by using the external tool setup shown
here:
http://www.dsource.org/projects/descent/wiki/CompilingPrograms



Well, I would like to just give it my dmd path and have it just work. I  
haven't managed to get rebuild to work yet. I think it has major problems  
with directories with spaces, and I do all my work in a folder within my  
user profile on Windows XP. This directory has spaces in it.


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


Re: looking for an IDE

2009-09-29 Thread Phil Deets
On Tue, 29 Sep 2009 20:09:44 -0500, Jeremie Pelletier   
wrote:



Phil Deets wrote:
Hi, I'm new to D and am mostly interested in D2. Is there a Windows IDE  
with support for D2 debugging, building, and basic code navigation  
(such as go to definition)? I've been trying a couple different IDEs,  
but most seem to be focused towards D1. Another nice to have "feature"  
would be support for keeping everything in a directory with spaces. I  
put feature in quotes because I consider it a bug if it does not  
support that.




I have yet to find such an IDE on windows, I use poseidon for its simple  
project manager and syntax highlighting (I had to add the latest D2  
keywords manually), but it has no semantics analysis and the ddbg  
support is half broken so I debug with windbg, however its very light  
and very fast.


I hear Descent for Eclipse is getting support for D2 so you might want  
to start looking there, it does semantics analysis but Eclipse is too  
heavy an IDE for my tastes. I can't tell if it has jump to definition.


Jeremie


I tried Descent, but it didn't work well at all with my D2 program. It  
also didn't support building. I'll look into Poseidon. Thanks.


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


looking for an IDE

2009-09-29 Thread Phil Deets
Hi, I'm new to D and am mostly interested in D2. Is there a Windows IDE  
with support for D2 debugging, building, and basic code navigation (such  
as go to definition)? I've been trying a couple different IDEs, but most  
seem to be focused towards D1. Another nice to have "feature" would be  
support for keeping everything in a directory with spaces. I put feature  
in quotes because I consider it a bug if it does not support that.


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/