Re: How array concatenation works... internally

2018-04-23 Thread Dnewbie via Digitalmars-d-learn
On Monday, 23 April 2018 at 23:27:17 UTC, Steven Schveighoffer 
wrote:

...
If you want to know more about the array runtime, I suggest 
this article: https://dlang.org/articles/d-array-article.html

...


Thanks for replying and this article is what I was looking for.


Re: How array concatenation works... internally

2018-04-23 Thread Dnewbie via Digitalmars-d-learn

On Monday, 23 April 2018 at 23:15:13 UTC, Dnewbie wrote:

It's related to memcpy?


By the way... It's related to realloc and memcpy?



How array concatenation works... internally

2018-04-23 Thread Dnewbie via Digitalmars-d-learn

Hi,

I'd like to understand how array concatenation works internally, 
like the example below:


//DMD64 D Compiler 2.072.2
import std.stdio;
void main(){
string[] arr;
arr.length = 2;
arr[0] = "Hello";
arr[1] = "World";
writeln(arr.length);
arr = arr[0..1] ~ "New String" ~ arr[1..2];
writeln(arr.length);
foreach(string a; arr){
writeln(a);
}
}
http://rextester.com/DDW84343

The code above prints:
2
3
Hello
New String
World


So, It changes the "arr" length and put the "New String" between 
the other two. It's very fast with some other tests that I made.


Now I'm curious to know what's happening under the hood. It's 
related to memcpy?


On Phobos "array.d" source I've found this:

/// Concatenation with rebinding.
void opCatAssign(R)(R another)
{
auto newThis = this ~ another;
move(newThis, this);
}

But now I'm having problem to find how I can reach this "move" 
function, since I couldn't find any "move" on the "std" folder.


Thanks in advance.


Re: Question about function aliases

2013-12-11 Thread dnewbie
On Wednesday, 11 December 2013 at 23:42:44 UTC, Gary Willoughby 
wrote:

For example i have some C code like this:

typedef void (Tcl_InterpDeleteProc) _ANSI_ARGS_((ClientData 
clientData, Tcl_Interp *interp));


void Tcl_CallWhenDeleted(Tcl_Interp* interp, 
Tcl_InterpDeleteProc* proc, ClientData clientData);



I intend on converted this to D thus:

alias void function(ClientData clientData, Tcl_Interp* interp) 
Tcl_InterpDeleteProc;


void Tcl_CallWhenDeleted(Tcl_Interp* interp, 
Tcl_InterpDeleteProc* proc, ClientData clientData);


Is it correct keeping the * with the Tcl_InterpDeleteProc 
parameter or do i remove it? Is the alias above a function 
pointer?


To call this function can i use a function literal for the 
Tcl_InterpDeleteProc parameter? or do i need to pass an address 
of the function?


It's a function pointer.
Test:

import std.stdio;
alias extern(C) void function(void*) Callback;

void Call(Callback c)
{
c(c);
}

extern(C) void callback(void* v)
{
writefln(v: %04X, v);
}

void main()
{
Callback c = callback;
Call(c);
writefln(c: %04X, c);
}


Re: Getting the missing Windows functions

2013-10-08 Thread dnewbie

On Tuesday, 8 October 2013 at 08:54:44 UTC, Mike Parker wrote:

On 10/8/2013 6:57 AM, Andrej Mitrovic wrote:

On 10/7/13, Matt webwra...@fastmail.fm wrote:
The missing functions (or at least the one I'm interested in 
at

the moment) that I'm trying to use are supposed to be IN
kernel32, and have been in there since Windows Vista. That's 
why

I'm a little confused.


The kernel32.lib distributed with DMD is likely out of date.
See: http://d.puremagic.com/issues/show_bug.cgi?id=6625



It's very out of date. When I need Windows functions that are 
missing from the DMD libs, I prototype them as function 
pointers and load them dynamically. It's a one-off investment 
for each function and I don't need many of them, so no big deal.


I always run this when I install a new dmd
cd C:\D\dmd2\windows\lib\
coffimplib C:\Program Files (x86)\Microsoft 
SDKs\Windows\v7.0A\Lib\advapi32.lib advapi32.lib
coffimplib C:\Program Files (x86)\Microsoft 
SDKs\Windows\v7.0A\Lib\comctl32.lib comctl32.lib
coffimplib C:\Program Files (x86)\Microsoft 
SDKs\Windows\v7.0A\Lib\comdlg32.lib comdlg32.lib
coffimplib C:\Program Files (x86)\Microsoft 
SDKs\Windows\v7.0A\Lib\gdi32.libgdi32.lib
coffimplib C:\Program Files (x86)\Microsoft 
SDKs\Windows\v7.0A\Lib\kernel32.lib kernel32.lib
coffimplib C:\Program Files (x86)\Microsoft 
SDKs\Windows\v7.0A\Lib\shell32.lib  shell32.lib
coffimplib C:\Program Files (x86)\Microsoft 
SDKs\Windows\v7.0A\Lib\shlwapi.lib  shlwapi.lib
coffimplib C:\Program Files (x86)\Microsoft 
SDKs\Windows\v7.0A\Lib\user32.lib   user32.lib
coffimplib C:\Program Files (x86)\Microsoft 
SDKs\Windows\v7.0A\Lib\ws2_32.lib   ws2_32.lib
coffimplib C:\Program Files (x86)\Microsoft 
SDKs\Windows\v7.0A\Lib\wsock32.lib  wsock32.lib


Re: How to cleanup after Socket.bind on Linux?

2013-08-26 Thread dnewbie

On Tuesday, 27 August 2013 at 03:30:11 UTC, Ali Çehreli wrote:
It cannot be started a second time for 8080 still being in use, 
unless you wait for several seconds


It works on Windows7, no need to wait.


Re: DLLs: Cleaning up

2013-07-11 Thread dnewbie

On Thursday, 11 July 2013 at 12:58:42 UTC, Chris wrote:
I have a DLL written in D I load into a Python application via 
ctypes like so:


lib = CDLL(mydll)

The DLL loads and can be used no problem. However, once the DLL 
is discarded of by the program, the program either doesn't 
react or crashes. I still haven't worked out how to clean up 
the DLL correctly before it is unloaded / detached (from 
Python). I guess it's the GC and/or some C stuff I've 
overlooked. I have tried both approaches described on this 
page: http://dlang.org/dll.html.


Maybe someone of yous once had a similar problem and found a 
solution. Any hints or suggestions would be appreciated. Thanks.


Ye. Please try compiling your DLL with GDC.


Re: x64 Link Issues - Can someone please help?

2013-04-19 Thread dnewbie

phobos64.lib(dmain2_4ac_1a5.obj) : error LNK2019: unresolved
external symbol _Dmain referenced in function main


Please add -L/DLL to the command line.


Trouble with DLL address

2013-01-14 Thread dnewbie
I have a DLL which exports a function GetFunction. GetFunction 
returns a pointer to RealFunction. Now I want to run RealFunction 
from my D program, but for some reason I get the wrong address. 
Here is the code.


 dll64.c -
#define WIN32_LEAN_AND_MEAN
#include windows.h

int __stdcall RealFunction(int a)
{
return a + 1;
}

typedef int (__stdcall *FuncPtr)(int);

FuncPtr __stdcall GetFunction()
{
return RealFunction;
}

 mydll64.def 
LIBRARY mydll64.dll
EXPORTS
GetFunction
-

build with MSVC64:
cl -c dll64.c -Fomydll64.obj
link /DLL /OUT:mydll64.dll mydll64.obj /DEF:mydll64.def

And this is the D program.

 testdll64d.d 
// dmd -m64 -c testdll64d.d -oftestdll64d.obj
// link /OUT:testdll64d.exe testdll64d.obj

import core.runtime;
import std.c.windows.windows;
import std.stdio;

alias extern(Windows) int function(int) FuncPtr;

int main(string[] args)
{
HMODULE dll  = LoadLibraryA(mydll64.DLL);
FARPROC getFunction  = GetProcAddress(dll, GetFunction);
FuncPtr realFunction = cast(FuncPtr) getFunction();

writefln(dll address:  %08x, dll);
writefln(GetFunction address:  %08x, getFunction);
writefln(RealFunction address: %08x, realFunction);
writefln(RealFunction result:  %d,   realFunction(7));//-- 
CRASH


return 0;
}
--

Output:
dll address:  18000
GetFunction address:  180001020
RealFunction address: 80001000
CRASH

BTW, this works:
FuncPtr realFunction = cast(FuncPtr) (getFunction()  
0x | cast(size_t) dll);


Re: Trouble with DLL address

2013-01-14 Thread dnewbie

The problem is FARPROC. Thank you everybody.

Solution:
import core.runtime;
import std.c.windows.windows;
import std.stdio;

alias extern(Windows) int function(int) FuncPtr;
alias extern(Windows) FuncPtr function() GetFuncPtr;

int main(string[] args)
{
HMODULE dll= LoadLibraryA(mydll64.DLL);
	GetFuncPtr getFunction = cast(GetFuncPtr) GetProcAddress(dll, 
GetFunction);	

FuncPtr realFunction   = cast(FuncPtr) getFunction();

writefln(dll address:  %08x, dll);
writefln(GetFunction address:  %08x, getFunction);
writefln(RealFunction address: %08x, realFunction);
writefln(RealFunction result:  %d,   realFunction(7));

return 0;   
}



Re: #define trouble

2012-11-27 Thread dnewbie

On Tuesday, 27 November 2012 at 06:27:49 UTC, Ali Çehreli wrote:

On 11/26/2012 10:05 PM, dnewbie wrote:

I have the following C struct from ldap.h

typedef struct ldapmod {
int mod_op;
char *mod_type;
union mod_vals_u {
char **modv_strvals;
struct berval **modv_bvals;
} mod_vals;
#define mod_values mod_vals.modv_strvals
#define mod_bvalues mod_vals.modv_bvals
} LDAPMod;

It is used like this:
LDAPMod title;
title.mod_values = x;

I wonder how can I write the line 'title.mod_values = x;' in D.
Currently I do like this:

struct ldapmod {
int mod_op;
char* mod_type;
union mod_vals_u {
char** modv_strvals;
berval** modv_bvals;
}
mod_vals_u mod_vals;
}
alias ldapmod LDAPMod;

LDAPMod title;
title.mod_vals.modv_strvals = x;




A pair of @property functions would work, one of which may be 
unnecessary:


alias int berval;

struct ldapmod {
intmod_op;
char* mod_type;
union mod_vals_u {
char**  modv_strvals;
berval** modv_bvals;
}
mod_vals_u mod_vals;

char** mod_values() @property
{
return mod_vals.modv_strvals;
}

void mod_values(char** value) @property
{
mod_vals.modv_strvals = value;
}

// similarly for mod_bvalues...
}
alias ldapmod LDAPMod;

void main()
{
LDAPMod title;
char** x;
// title.mod_vals.modv_strvals = x;
title.mod_values = x;
}


Ali



Perfect! Thank you.




#define trouble

2012-11-26 Thread dnewbie

I have the following C struct from ldap.h

typedef struct ldapmod {
int mod_op;
char *mod_type;
union mod_vals_u {
char **modv_strvals;
struct berval **modv_bvals;
} mod_vals;
#define mod_values  mod_vals.modv_strvals
#define mod_bvalues mod_vals.modv_bvals
} LDAPMod;

It is used like this:
LDAPMod title;
title.mod_values = x;

I wonder how can I write the line 'title.mod_values = x;' in D.
Currently I do like this:

struct ldapmod {
int mod_op;
char* mod_type;
union mod_vals_u {
char**  modv_strvals;
berval** modv_bvals;
}
mod_vals_u mod_vals;
}
alias ldapmod LDAPMod;

LDAPMod title;
title.mod_vals.modv_strvals = x;




Re: WinAPI LowLevel Keyboard Hooks

2012-07-19 Thread dnewbie

On Thursday, 19 July 2012 at 15:49:48 UTC, DLimited wrote:
But what are the differences of loading the Unicode version vs. 
the ANSI version? I called the Unicode one because I figured 
that would be the sensible choice, since Unicode is the default 
for D (if I remember correctly). I have no clue what the actual 
effects of calling the wrong version would be.


Anyway, here's the of my .dll:

 -- Code begin -- 

import std.c.windows.windows;
import core.sys.windows.dll;
import core.runtime;


extern (C) void gc_init();
extern (C) void gc_term();
extern (C) void _minit();
extern (C) void _moduleCtor();
extern (C) void _moduleDtor();

extern (Windows) struct KBDLLHOOKSTRUCT {
  DWORD vkCode;
  DWORD scanCode;
  DWORD flags;
  DWORD time;
  ULONG_PTR dwExtraInfo;
};
extern (Windows) LRESULT CallNextHookEx(
int function() hhk,
  int nCode,
   WPARAM wParam,
LPARAM lParam
);


__gshared HINSTANCE g_hInst;


 extern (Windows) BOOL DllMain(HINSTANCE hInstance, ULONG 
ulReason, LPVOID pvReserved) {

return true;
switch (ulReason) {
case DLL_PROCESS_ATTACH:
g_hInst = hInstance;
Runtime.initialize;
//dll_process_attach( hInstance, true );
break;

case DLL_PROCESS_DETACH:
dll_process_detach( hInstance, true );
break;

case DLL_THREAD_ATTACH:
dll_thread_attach( true, true );
break;
case DLL_THREAD_DETACH:
dll_thread_detach( true, true );
break;

default:
return true;
}
return true;
}

extern (Windows) LRESULT LowLevelKeyboardProc(int code, WPARAM 
wParam, LPARAM lParam)

{
KBDLLHOOKSTRUCT* details = cast(KBDLLHOOKSTRUCT*) lParam;
MessageBoxA(null, cast(char *)WHOA, Error,
MB_OK | MB_ICONEXCLAMATION);
if(code == 0  wParam == WM_KEYDOWN)
{
if(details.vkCode == 0x41)
{

return 1;
}
}

return CallNextHookEx(null, code, wParam, lParam);
}

 -- Code End -- 

Lots of copypaste was used. I injected some senseless code to 
try and check if a specific function ever gets called, though I 
now realise the DllLoad itself is what fails. Haven't cleaned 
it back up yet, though.


The .def file contains the following: (including newlines)

 -- .DEF BEGIN -- 
LIBRARY keydll.dll
EXETYPE NT
SUBSYSTEM WINDOWS
CODE PRELOAD
DATA PRELOAD
 -- .DEF END   -- 


I compiled the dll using:
dmd -ofkeydll.dll -L/IMPLIB keydll.d keydll.def

No linker/compiler errors.


I guess you have to 'export' the function:
extern (Windows) export LRESULT LowLevelKeyboardProc(int code, 
WPARAM

wParam, LPARAM lParam)

and include
EXPORTS
  LowLevelKeyboardProc

in the .DEF file





Re: WinAPI LowLevel Keyboard Hooks

2012-07-19 Thread dnewbie

You don't see the WHOA message?
Try this
alias HANDLE HHOOK;


Re: WinAPI LowLevel Keyboard Hooks

2012-07-19 Thread dnewbie

On Thursday, 19 July 2012 at 17:48:06 UTC, DLimited wrote:

On Thursday, 19 July 2012 at 17:35:29 UTC, dnewbie wrote:

You don't see the WHOA message?
Try this
alias HANDLE HHOOK;


No, I don't get any message after key-presses. I changed int 
function() to HANDLE, sadly it still doesn't work.



For some reason, it doesn't work with 'Thread.sleep'
This works:
http://dpaste.dzfl.pl/1e6e5960






Re: WinAPI LowLevel Keyboard Hooks

2012-07-19 Thread dnewbie

On Thursday, 19 July 2012 at 18:56:15 UTC, DLimited wrote:

On Thursday, 19 July 2012 at 18:40:15 UTC, dnewbie wrote:

On Thursday, 19 July 2012 at 17:48:06 UTC, DLimited wrote:

On Thursday, 19 July 2012 at 17:35:29 UTC, dnewbie wrote:

You don't see the WHOA message?
Try this
alias HANDLE HHOOK;


No, I don't get any message after key-presses. I changed int 
function() to HANDLE, sadly it still doesn't work.



For some reason, it doesn't work with 'Thread.sleep'
This works:
http://dpaste.dzfl.pl/1e6e5960


It doesn't work for me. I can 1 Message Box from the Code in 
MyWinMain, but none for the Keystrokes. I registered a hook for 
Keyboard input, and that code is supposed to produce a message 
box aswell. The function for that is called 
LowLevelKeyboardProc and located in above-mentioned .dll file.


The registering of the hook seems to pass, but the function 
never actually gets called.


Did you add
EXPORTS
LowLevelKeyboardProc

to the .DEF file?
It works here.




Re: WinAPI LowLevel Keyboard Hooks

2012-07-19 Thread dnewbie

On Thursday, 19 July 2012 at 19:51:31 UTC, DLimited wrote:

Yes, I did. Are the newlines important?

And you really get a MessageBox per keystroke? I start as 
admin, disabled my AV but still, no success.


Yes, I get 2 WHOA messages. One from the WM-KEYDOWN and the 
other from WM-KEYUP.

Sorry I don't know what is wrong.


Re: Winamp plugin

2012-07-12 Thread dnewbie

On Friday, 6 July 2012 at 00:38:28 UTC, dnewbie wrote:

It works without error when compiled by GDC.
Thanks.


Here it is
http://my.opera.com/run3/blog/2012/07/12/copyto-winamp-plugin

It adds an item in Winamp 'Send to' menu


Re: Linking OpenSSL on Windows

2012-07-08 Thread dnewbie

On Sunday, 8 July 2012 at 22:33:15 UTC, Andy wrote:
I've been using D on linux for a few months now and have the 
hang of it. I wrote a project that should be able to be 
compiled on both Linux and Windows. I've gotten it to work 
excellently on Linux, but I can't seem to figure out how to 
link the openssl dll files on Windows. On linux, a simple 
passing of -lssl and -lcrypto the ld works great, but what do I 
need to do for this to work with optlink?


I think you need to generate an import library from the openssl 
dll file, then use the generated .lib file in optlink command 
line, see http://www.digitalmars.com/ctg/implib.html


Re: Winamp plugin

2012-07-05 Thread dnewbie
On Thursday, 5 July 2012 at 08:55:33 UTC, Denis Shelomovskij 
wrote:


What's your OS? If Windows XP, than D DLL can't be unloaded 
because of non-perfect TLS fixing technique (I created a 
perfect one but I never managed to prepare such projects for 
release so nobody knows about them).


And on any Windows Digital Mars C runtime behaves very nasty 
when it's dynamically loaded. IIRC, it do bad things when 
loaded in non-main with TLS index != 0 thread and when unloaded 
(IIRC, again, at least it closes handles).


Hi. OS is Windows7-64bit.
When I run Winamp in windbg, windbg crashes. The last information 
I can see is

'Module Unload: C:\WINDOWS\WINSXS\X86_\MSVCR90.DLL'
Thanks.



Re: Winamp plugin

2012-07-05 Thread dnewbie

It works without error when compiled by GDC.
Thanks.



Winamp plugin

2012-07-04 Thread dnewbie
I'm writing a Winamp plugin in D. Winamp loads my plugin and 
everything is fine until I close Winamp. At this point, Winamp 
calls the Quit() function of my plugin and *after* that, Winamp 
crashes.


Here is the code.

D source
http://dpaste.dzfl.pl/e2b2f886


myplugin.def - .DEF file
---
LIBRARY ml_myplugind.dll
EXETYPE NT
SUBSYSTEM WINDOWS
EXPORTS
winampGetMediaLibraryPlugin
---

Compile:
dmd myplugin.d myplugin.def -ofml_myplugind.dll -L/IMPLIB

Copy ml_myplugind.dll to 'C:\Program Files (x86)\Winamp\Plugins'

Restart Winamp and go to Options - Preferences - Plugins - 
Media Library.
You'll see 'My Cool Plugin D' [ml_myplugind.dll]' that means the 
plugin was loaded.


Close Winamp. You'll see a message box 'Quit() from D', from the 
plugin and
MS-Windows displays a error dialog. Click more information and it 
says APPCRASH module ml_myplugind.dll.


I have tried the following C code which does the same thing, and 
I've got no APPCRASHES


http://pastebin.com/7t8jkfn8

I can't see what is wrong. Any help is appreciated.

More information about Winamp plugin:
http://wiki.winamp.com/wiki/Media_Library_Plugin



Re: Build WindowsApi bindings with dmd?

2012-07-02 Thread dnewbie

On Monday, 2 July 2012 at 22:10:00 UTC, Damian wrote:
I was looking through the bindings and only see a makefile for 
GNU make.
Is there a version for dmd? I really wanted to avoid GNU make 
if possible.


You can try this
https://github.com/AndrejMitrovic/WindowsAPI/downloads



Re: function pointer when a function is overloaded.

2012-06-30 Thread dnewbie

import std.stdio;

alias void function(int) fooInt;
alias void function(long) fooLong;

int main(string[] args)
{
fooInt  f1 = foo;
fooLong f2 = foo;
f1(1L);
f2(1L);
return 0;
}

void foo(int i)
{
writeln(foo(int i));
}

void foo(long i)
{
writeln(foo(long i));
}


Re: Windows - ZeroMemory macro

2012-05-27 Thread dnewbie

On Sunday, 27 May 2012 at 03:55:58 UTC, jerro wrote:

On Sunday, 27 May 2012 at 03:29:17 UTC, dnewbie wrote:

In C I can write

OPENFILENAME ofn;
ZeroMemory(ofn, sizeof(ofn));

In D, there is no ZeroMemory. Please help me.


You could use c memset:

import std.c.string;
memset(cast(void*)ofn, 0, ofn.sizeof);

or this:

(cast(byte*) a)[0 .. a.sizeof] = 0;


Thank you.


Windows - ZeroMemory macro

2012-05-26 Thread dnewbie

In C I can write

OPENFILENAME ofn;
ZeroMemory(ofn, sizeof(ofn));

In D, there is no ZeroMemory. Please help me.


Re: libraries and c++ compatibility

2012-05-13 Thread dnewbie

On Sunday, 13 May 2012 at 02:44:22 UTC, Jason King wrote:
I'm trying to use ocilib (deimos\ocilib) bindings and having 
some issues.

dmd 2.0.59, Windows 7 64 bit.
I can change sc.ini to get everything to build.
I can compile with dmd myapp.d -Ipath_to_deimos -c, but I 
can't seem to figure out the right switches to make the app 
find the ociliba-dm.lib that I generated.
Using sc.ini seems to work, using the lib environment variable 
seems to work but I'd like to understand how to make the 
command line switches work.


The compiled application hangs the first time it calls an 
ocilib routine and I don't expect you folks to debug that for 
me but it occurred to me that since I have the paid-for version 
of dmc I could try essentially the same code vs. c++ and if it 
worked that would isolate the problem to the ocilib.d header.


I have the same can't find the library with command line 
switches problem but I suspect the D fix will help me c++-wise 
as well.  The unique to c++ issue is shows like so.
C:\ocilib\ocilib3.9.3\lib32dmc myapp.cpp -c 
-Ic:\ocilib\ocilib3.9.3\include


C:\ocilib\ocilib3.9.3\lib32optlink myapp.obj,,,ociliba-dm.lib
OPTLINK (R) for Win32  Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

myapp.obj(myapp)
 Error 42: Symbol Undefined _OCI_Cleanup
myapp.obj(myapp)
 Error 42: Symbol Undefined _OCI_GetString
... 7 more, covering all ocilib calls.

running lib -l vs. ociliba-dm.lib shows symbols with @ signs 
appended, e.g.

_OCI_Cleanup@0 and _OCI_GetString@8.
I suspect there's some simple disconnect on my part here, but I 
can't see it.

Any assistance deeply appreciated.



Please try adding `-DOCI_API=__stdcall -DOCI_CHARSET_ANSI` to dmc 
command line. (check 
http://orclib.sourceforge.net/doc/html/group__g__install.html)


If you get runtime errors, please check your ORACLE_HOME 
environment variable and make sure your %ORACLE_HOME%\bin 
directory is in your PATH environment variable.






Re: libraries and c++ compatibility

2012-05-13 Thread dnewbie

On Sunday, 13 May 2012 at 19:01:15 UTC, Jason King wrote:

.
C:\ocilib\ocilib3.9.3\lib32dmc myapp.cpp -c 
-Ic:\ocilib\ocilib3.9.3\include


C:\ocilib\ocilib3.9.3\lib32optlink myapp.obj,,,ociliba-dm.lib
OPTLINK (R) for Win32  Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

myapp.obj(myapp)
Error 42: Symbol Undefined _OCI_Cleanup
myapp.obj(myapp)
Error 42: Symbol Undefined _OCI_GetString
... 7 more, covering all ocilib calls.



Please try adding `-DOCI_API=__stdcall -DOCI_CHARSET_ANSI` to 
dmc command line. (check 
http://orclib.sourceforge.net/doc/html/group__g__install.html)


If you get runtime errors, please check your ORACLE_HOME 
environment variable and make sure your %ORACLE_HOME%\bin 
directory is in your PATH environment variable.

Thanks for the help.

All I did was generate a OMF library running IMPLIB vs. 
OCILIBA.DLL.
I think your suggestion involves building OCILIB from scratch.  
Is that right?



No. You should add '-DOCI_API=__stdcall -DOCI_CHARSET_ANSI' to 
dmc when building your c/cpp app.



Rebuilding the library looks like a job and I want to make sure 
that's what I need to do to proceed.





Re: mysql binding/wrapper?

2012-04-29 Thread dnewbie

On Saturday, 28 April 2012 at 15:30:13 UTC, simendsjo wrote:
stuff/blob/master/mysql.d

http://my.opera.com/run3/blog/2012/03/13/d-mysql


I use it in a bank account application. It works.


Re: string concatenation

2012-04-08 Thread dnewbie

On Sunday, 8 April 2012 at 05:27:50 UTC, Jonathan M Davis wrote:

On Sunday, April 08, 2012 07:08:09 dnewbie wrote:

I have a wchar[] and I want to convert it to UTF8
then append a string. This is my code.

import std.c.windows.windows;
import std.string;
import std.utf;

int main()
{
   wchar[100] v;
   v[0] = 'H';
   v[1] = 'e';
   v[2] = 'l';
   v[3] = 'l';
   v[4] = 'o';
   v[5] = 0;
   string s = toUTF8(v) ~ , world!;
   MessageBoxA(null, s.toStringz, myapp, MB_OK);
   return 0;
}

I want Hello, world!, but the result is Hello only. Please 
help me.


D strings are not null-terminated, so v[5] = 0 doesn't do 
anything to
terminate that string. The whole point of toStringz is to put a 
null character
on the end of a string (and allocate a new string if need be) 
and return a
pointer to it. C code will then use the null character to 
indicate the end of

the string, but D won't.

What you've done with

string s = toUTF8(v) ~ , world!;

is create a string that is

['H', 'e', 'l', 'l', 'o', '\0', '\0', '\0', ...] (all of the 
characters up to

the v[99] are '\0')

and append

[',', ' ', 'w', 'o', 'r', 'l', 'd', '!']

to it. The result is a string whith is 108 characters long with 
a ton of null
characters in the middle of it. When you call toStringz on it, 
it may or may
not allocate a new string, but in the end, you have a string 
which is 109
characters long with the last character being '\0' (still with 
all of the null
characters in the middle) which you get an immutable char* 
pointing to.


So, when the C code operates on it, it naturally stops 
processing when it hits
the first null character, since that's how C determines the end 
of a string.
You can embed null characters in a string and expect C to 
operate on the whole
thing. And since D strings aren't null-terminated, you can't 
expect that
setting any of it their elements to null will do anything to 
terminate the
string in D or stop D functions from operating on the whole 
string. You have
to slice the static wchar array with the exact elements that 
you want if you

intend to terminate it before its end.

- Jonathan M Davis


OK. Thank you.


string concatenation

2012-04-07 Thread dnewbie
I have a wchar[] and I want to convert it to UTF8
then append a string. This is my code.

import std.c.windows.windows;
import std.string;
import std.utf;

int main()
{
   wchar[100] v;
   v[0] = 'H';
   v[1] = 'e';
   v[2] = 'l';
   v[3] = 'l';
   v[4] = 'o';
   v[5] = 0;
   string s = toUTF8(v) ~ , world!;
   MessageBoxA(null, s.toStringz, myapp, MB_OK);
   return 0;
}

I want Hello, world!, but the result is Hello only. Please help me.


Re: Converting C .h Files to D Modules

2012-03-20 Thread dnewbie
On Wednesday, 21 March 2012 at 01:09:58 UTC, Andrej Mitrovic 
wrote:

On 3/21/12, Pedro Lacerda kanvua...@gmail.com wrote:
Ouch, void* is the same in both languages, sorry. I addressed 
a new problem:


typedef struct SomeFunctions {
void *(*funcA)(char*, size_t);
void *(*funcB)(void);
} SomeFunctions;

How do I convert that functions references into an D struct?


extern(C)
struct SomeFunctions {
void function(char*, size_t) funcA;
void function() funcB;
}

Use HTOD (http://dlang.org/htod.html) if you can to convert .h 
to .D

(it's Windows-only but might be usable via Wine).


Why not
 void* function(char*, size_t) funcA;
 void* function() funcB;



htod - const

2012-03-06 Thread dnewbie
I have this file tmp.h:

const char *getvalue(const char *key);

I run htod tmp.h and I've got the output

---
/* Converted to D from tmp.h by htod */
module tmp;
//C const char *getvalue(const char *key);
extern (C):
char * getvalue(char *key);
---

Why is 'const' removed?




Re: htod - const

2012-03-06 Thread dnewbie
Thanks Trass3r.

On Tue, Mar 6, 2012, at 05:50 PM, Trass3r wrote:
  Why is 'const' removed?
 
 cause htod sucks.
 D1 didn't have const and htod wasn't updated for ages.
 


Re: std.socket with GDC

2012-02-25 Thread DNewbie


On Sat, Feb 25, 2012, at 10:38 PM, Mars wrote:
 On Saturday, 25 February 2012 at 18:27:29 UTC, Vladimir Panteleev 
 wrote:
  On Friday, 24 February 2012 at 19:15:26 UTC, Mars wrote:
  Hello everybody.
 
  When trying to compile a program using GDC (Windows), which 
  includes an import std.socket, I get a lot undefined 
  references, like
 undefined reference to `WSAGetLastError@0'
 
  Try linking with libws2_32.a.
 
 Still the same. Does that work for you?
 

std.socket works for me,
gdc64 (windows)


Re: Examples of Windows services in D?

2012-02-22 Thread DNewbie
Here is a simple service in D
http://my.opera.com/run3/blog/2012/02/23/windows-services-in-d
It's basically c translated to d.


On Tue, Feb 21, 2012, at 03:08 PM, Graham Fawcett wrote:
 Hi folks,
 
 I've got a Windows service that I'd like to write in D, if possible. I 
 see that Andrej Mitrovic has provided a binding for the relevant parts of 
 the Windows API (thanks!):
 
 https://github.com/AndrejMitrovic/DWinProgramming/blob/master/win32/
 winsvc.d
 
 Has anyone used this (or another binding) to write an actual service? 
 Particularly, I was hoping to find a base class that takes care of 
 common tasks (installing, removing, starting, etc.).
 
 Thanks!
 Graham
 




Re: Socket: The connection was reset

2012-02-10 Thread DNewbie
nrgyzer,
please check the return value of 'receive'.

http://dlang.org/phobos/std_socket.html#receive



On Fri, Feb 10, 2012, at 02:06 PM, nrgyzer wrote:
 Works perfectly, thanks :)
 But... how can I read the complete HTTP-header? When I try the following:
 
   string header;
   ubyte[1024] buffer;
   while (cs.receive(buffer)) header ~= buffer;
 
 ... it works as long as the header doesn't have a length like 1024, 2048,
 3072... Otherwise cs.receive() blocks forever and the server doesn't
 respond
 anything. Is there any solution how to prevent/solve this problem?
 
 
 == Auszug aus DNewbie (r...@myopera.com)'s Artikel
  Try this
  while(true) {
  Socket cs = s.accept();
  cs.receive(new byte[1024]);
  cs.sendTo(HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nHello
 World);
  cs.close();
  }
  On Thu, Feb 9, 2012, at 07:31 PM, Nrgyzer wrote:
   Hi guys,
  
   I wrote the following few lines:
  
   private {
  
 import std.socket;
  
   }
  
   void main() {
  
 Socket s = new TcpSocket();
 s.bind(new InternetAddress(80));
 s.listen(0);
  
 while(true) {
  
 Socket cs = s.accept();
 cs.sendTo(HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nHello
 World);
 cs.close();
  
 }
  
 s.close();
  
   }
  
   The code compiles successfully and I also the server also responses with
   Hello World, but when I reload the page I sometimes get the following
   error (Firefox): The
   connection was reset - I also often get the same error in other
   browsers. Is there anything wrong with the code?
  
   Thanks in advance!
  
 
 


-- 
  
  D


Re: Socket: The connection was reset

2012-02-09 Thread DNewbie
Try this

while(true) {
Socket cs = s.accept();
cs.receive(new byte[1024]);
cs.sendTo(HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nHello 
World);
cs.close();
}



On Thu, Feb 9, 2012, at 07:31 PM, Nrgyzer wrote:
 Hi guys,
 
 I wrote the following few lines:
 
 private {
 
   import std.socket;
 
 }
 
 void main() {
 
   Socket s = new TcpSocket();
   s.bind(new InternetAddress(80));
   s.listen(0);
 
   while(true) {
 
   Socket cs = s.accept();
   cs.sendTo(HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nHello 
 World);
   cs.close();
 
   }
 
   s.close();
 
 }
 
 The code compiles successfully and I also the server also responses with
 Hello World, but when I reload the page I sometimes get the following
 error (Firefox): The
 connection was reset - I also often get the same error in other
 browsers. Is there anything wrong with the code?
 
 Thanks in advance!
 


-- 
  
  D


Re: i18n

2012-02-03 Thread DNewbie


On Fri, Feb 3, 2012, at 09:48 PM, Trass3r wrote:
  Thanks a lot, So I just need to detect user locale using How to do  
  that?
 
 You can always use the functions you would use in C.
 


You can see your language id in this page:
http://msdn.microsoft.com/en-us/library/dd318693(v=vs.85).aspx

Example
-
import std.stdio;
import std.c.windows.windows;
alias DWORD LCID;
extern (Windows) LCID GetSystemDefaultLCID();

int main()
{
  LCID lcid = GetSystemDefaultLCID();
  printf(GetSystemDefaultLCID = 0x%04X\n, lcid);

  switch (lcid)
  {
case 0x0409:
  writeln(United States (US));
break;

case 0x040c:
  writeln(France (FR));
break;

default:
  writeln(Unknown);
break;

  }
  return 0;
}
-




Re: MySQL

2012-01-22 Thread DNewbie


On Sun, Jan 22, 2012, at 12:11 AM, Ali Çehreli wrote:
 On 01/21/2012 06:28 PM, Mars wrote:
  On Sunday, 22 January 2012 at 00:50:28 UTC, Ali Çehreli wrote:
  Are you also including the library on the command line with -L-l? For
  example, for ncurses:
 
  dmd ... -L-lncurses ...
 
  And if needed, also -L-L to specify the location of library files for
  the linker.
 
  Ali
 
  Yes, I am including it. Tried pragma and command line. And I don't get a
  message that the lib couldn't be found.
  What exactly is -L-l supposed to do? Is this valid in DMD 2.057? I get
  an error with it (Unknown Option).
 
  Mars
 
 -L is dmd's the linker flag option. Anything after that is passed to the 
 linker. So -L-l passes -l to the linker:
 
http://www.d-programming-language.org/dmd-linux.html
 
 Ali
 


I've took a look at MySQL headers, the functions use __stdcall, but in 
libmysql.dll exports table they are not decorated.



Re: MySQL

2012-01-22 Thread DNewbie
On Sun, Jan 22, 2012, at 01:13 PM, Mars wrote:
 On Sunday, 22 January 2012 at 10:21:29 UTC, DNewbie wrote:
  I've took a look at MySQL headers, the functions use   stdcall, 
  but in libmysql.dll exports table they are not decorated.
 
 This means...?
 Shouldn't it at least compile, if they are listed in the def 
 file, coming from the lib?
 

You should add 'extern(Windows)', but it would not work anyway.
Can someone confirm the oplink does not handle this type of module (undecorated 
stdcall functions)?




Re: MySQL

2012-01-22 Thread DNewbie


On Sun, Jan 22, 2012, at 11:02 PM, DNewbie wrote:
 On Sun, Jan 22, 2012, at 01:13 PM, Mars wrote:
  On Sunday, 22 January 2012 at 10:21:29 UTC, DNewbie wrote:
   I've took a look at MySQL headers, the functions use   stdcall, 
   but in libmysql.dll exports table they are not decorated.
  
  This means...?
  Shouldn't it at least compile, if they are listed in the def 
  file, coming from the lib?
  
 
 You should add 'extern(Windows)', but it would not work anyway.
 Can someone confirm the oplink does not handle this type of module
 (undecorated stdcall functions)?
 
 
 

You can try

// - libmysql.def ---
LIBRARY libmysql.dll
EXETYPE NT
SUBSYSTEM WINDOWS
EXPORTS
_mysql_init@4=mysql_init
// 

// --- mysqltest.d 
import libmysql;
alias void MYSQL;

int main()
{
  MYSQL *m = libmysql.mysql_init(null);
  return 0;
}
// ---

// --- libmysql.di ---
alias void MYSQL;
export extern (Windows) MYSQL *mysql_init(MYSQL *);
// 

$ implib /system libmysql.lib libmysql.def
$ dmd mysqltest.d libmysql.lib

It works..



Re: MySQL

2012-01-21 Thread DNewbie
Please check whether your MySQL lib is 64 bit and your app is 32 bit.


On Sat, Jan 21, 2012, at 10:38 PM, Mars wrote:
 Hello everyone.
 I've been trying to use MySQL in an application on Windows, but I 
 always get
  Symbol Undefined _mysql_init
 I've put the lib in the correct folder, so I don't know what the 
 problem might be. I've tried several libs, and tried to compile 
 it myself (always converted using coffimplib), but it fails, no 
 matter what. I've also tried to make a def file out of the lib, 
 and the functions are definitly listed as exports there.
 Any idea what I might doing wrong?
 
 Mars
 


-- 
  
  D


Re: OOP Windows

2012-01-16 Thread DNewbie
On Mon, Jan 16, 2012, at 05:59 PM, Andrej Mitrovic wrote:
 On 1/16/12, Robert Clipsham rob...@octarineparrot.com wrote:
  https://github.com/AndrejMitrovic/DWinProgramming
 
 I think he's looking for an OOP approach, that code is basically C
 translated to D.
 
 There are some OOP libraries he can use, like DGUI or DFL. And there
 are some OOP wrappers for WinAPI somewhere (probably on dsource).
 Maybe http://pr.stewartsplace.org.uk/d/sdwf/ or
 http://www.dsource.org/projects/minwin. I think these two might be
 slightly outdated by now though.
 

Yes. I know a bit of C (not C++) and the Windows API. Now I'd like to learn 
more about OOP.
That's what I've found so far, both are for C++ programmers

http://win32-framework.sourceforge.net/
http://relisoft.com/win32/

Wel..I'm not sure. Should I learn C++ before D? Thank you everybody.


OOP Windows

2012-01-15 Thread DNewbie
Is there a D version of this type of tutorial?
https://www.relisoft.com/win32/index.htm


Re: A tutorial on D templates

2012-01-14 Thread DNewbie
On Sat, Jan 14, 2012, at 09:07 AM, Philippe Sigaud wrote:
  On 13/01/12 10:48 PM, DNewbie wrote:
   I can't understand it. Why would someone need template programming. What 
   problem does template solve?
 
 Well read on and see :-)
 
 Peter:
  Suppose you want to write a function to get the minimum of two integers.
  It's easy:
 
  Oh.. I see.
  Thank you everybody.
 
 And that's the first, more visible part of templates, a bit like
 generics in Java.
 Template are incomplete pieces of code with left-empty 'slots' which
 you can fill at compile-time to decide what code will be compiled.
 You can generate entire functions / class hierarchies or nicely
 crafted-for-your-need code / pre-computed-by-the-compiler code with
 templates.
 
 Philippe
 

OK... I won't play with templates for now, but please keep up the good work.


Re: import std.c.windows.windows;

2012-01-14 Thread DNewbie


On Wed, Jan 11, 2012, at 01:16 PM, Mike Parker wrote:
 On 1/10/2012 10:57 PM, DNewbie wrote:
  On Tue, Jan 10, 2012, at 10:37 PM, Mike Parker wrote:
 
  Those samples use a binding to the Win32 API[1] that does not ship with
  DMD. So in your case, std.c.windows.windows is probably what you want
  for now.
 
 
  [1]http://dsource.org/projects/bindings/wiki/WindowsApi
 
 
  Ok.. I still don't understand why such a 'binding' is needed.
  Is std.c.windows.windows not enough for everyone?
 
 
 Unfortunately, no. It is not a complete binding of the Win32 API. It has 
 a lot of stuff, but if you need more you need to look elsewhere. Andrej 
 hit on some of the deficiencies in his post.
 

Understood. I think I'll go with the binding. Thnk you.


Re: A tutorial on D templates

2012-01-13 Thread DNewbie
I can't understand it. Why would someone need template programming. What 
problem does template solve?
-- 
  
  D


Re: A tutorial on D templates

2012-01-13 Thread DNewbie


On Fri, Jan 13, 2012, at 11:28 PM, Peter Alexander wrote:
 On 13/01/12 10:48 PM, DNewbie wrote:
  I can't understand it. Why would someone need template programming. What 
  problem does template solve?
 
 Suppose you want to write a function to get the minimum of two integers. 
 It's easy:

Oh.. I see.
Thank you everybody.


function pointer from DLL

2012-01-13 Thread DNewbie
I've been trying to translate the following from 
http://www.scintilla.org/Steps.html

int (*fn)(void*,int,int,int);
void * ptr;
int canundo;

fn = (int (__cdecl *)(void *,int,int,int))SendMessage(
hwndScintilla,SCI_GETDIRECTFUNCTION,0,0);
ptr = (void *)SendMessage(hwndScintilla,SCI_GETDIRECTPOINTER,0,0);
canundo = fn(ptr,SCI_CANUNDO,0,0);


And I got a run time error while running 'fn(ptr, SCI_CANUNDO, 0, 0);':

int function (void*,int,int,int) fn;
fn = cast(int function(void*,int,int,int)) SendMessage(
hwndScintilla, SCI_GETDIRECTFUNCTION, 0, 0);

void *ptr = cast(void *)SendMessage(hwndScintilla, SCI_GETDIRECTPOINTER, 0, 0);

fn(ptr, SCI_CANUNDO, 0, 0);
Run time error: object.Error: Access Violation


Then I've tried
extern (C) int function (void*,int,int,int) fn; 
fn = cast(extern (C) int function(void*,int,int,int))SendMessage(
hwndScintilla, SCI_GETDIRECTFUNCTION, 0, 0);
Compilation error: basic type expected, not extern

Could someone point me in the right direction.



Re: function pointer from DLL

2012-01-13 Thread DNewbie

On Sat, Jan 14, 2012, at 06:04 AM, Andrej Mitrovic wrote:
 On 1/14/12, Andrej Mitrovic andrej.mitrov...@gmail.com wrote:
  You can clone this: g...@github.com:AndrejMitrovic/DSciteWin.git
 
  Then just run build.bat.
 
 
 Sorry, I've assumed you run git, the http link is:
 https://github.com/AndrejMitrovic/DSciteWin
 


Yeah! Rock'n'roll!
Thank you.





import std.c.windows.windows;

2012-01-10 Thread DNewbie
I'm not sure I understand.. The page at http://dlang.org/windows.html says

  Instead of the:
  #include windows.h
  of C, in D there is:
  import std.c.windows.windows;

However, the samples at 
https://github.com/AndrejMitrovic/DWinProgramming/tree/master/Samples
use

  import win32.windef;
  import win32.winuser;

My question is which one should I use in my programs?

-- 

  D


Re: import std.c.windows.windows;

2012-01-10 Thread DNewbie
On Tue, Jan 10, 2012, at 10:37 PM, Mike Parker wrote:
 
 Those samples use a binding to the Win32 API[1] that does not ship with 
 DMD. So in your case, std.c.windows.windows is probably what you want 
 for now.
 
 
 [1]http://dsource.org/projects/bindings/wiki/WindowsApi
 

Ok.. I still don't understand why such a 'binding' is needed.
Is std.c.windows.windows not enough for everyone?

-- 
  
  D


Re: Mixing D and C - Windows

2012-01-02 Thread DNewbie
Thank you both.

I've created a D DLL [http://dlang.org/dll.html], then I've loaded it from a C 
program [compiled with dmc].
However, I'd want to be able to call it from a C program compiled with MSVC, 
and I got a link error - unresolved external symbol [link testdll.obj 
/implib:mydll.lib /out:testdll-msvc.exe]. The LoadLibrary works with both 
DMC/MSVC, but it isn't 'handy'.?.



On Sat, Dec 31, 2011, at 07:20 PM, Exec wrote:
 Jakob Ovrum Wrote:
  As for loading C symbols in a DLL from a D program, you must link 
  against an import library of the DLL, and create an interface 
  module (similar to a header file) with the C declarations.
 Alternatively, you can load the DLL via the Windows API.
 http://msdn.microsoft.com/en-us/library/windows/desktop/ms684175%28v=vs.85%29.aspx
 


-- 
  
  D


Re: Mixing D and C - Windows

2012-01-02 Thread DNewbie
Resolved.
Thanks everyone.


On Tue, Jan 3, 2012, at 04:49 AM, Andrej Mitrovic wrote:
 Maybe I'm wrong, but IIRC objconv won't work on import libs.
 
 But there are other ways to do it: http://support.microsoft.com/kb/131313
 


-- 
  
  D