LDC2 compiling executable requiring elevated privileges?

2018-10-14 Thread spikespaz via Digitalmars-d
I'm compiling an executable that does not need administrator 
privileges. For some reason though, LDC thinks it does and marks 
it as elevated.


=
ldc2 source\setup.d -i -I source -J build\vars -of 
build\bin\setup.exe -m32 -g

=

No clue why, but what can I do about that?

I'm thinking maybe it's because I'm importing 
"std.windows.registry". But even then, I'm only writing to 
"HKEY_CURRENT_USER", so no elevation should be required.


This is the source.
https://github.com/spikespaz/search-deflector/blob/master/source/setup.d


LDC2 -I option results in unresolved externals

2018-10-12 Thread spikespaz via Digitalmars-d-learn
I'm using the latest LDC2 beta, and when running the compiler 
with -I (Look for imports also in ) it fails with 
unresolved externals. These are my commands.


=

$ ldc2 "source\setup.d" -I "source" -J "build\vars" -of 
"build\bin\setup.exe" -m32 -g
setup.obj : error LNK2019: unresolved external symbol 
__D6common17createErrorDialogFxC9ExceptionZv referenced in 
function __Dmain
setup.obj : error LNK2019: unresolved external symbol 
__D6common14getConsoleArgsFxPuZAAya referenced in function 
__D5setup20getAvailableBrowsersFZ14__foreachbody1MFKC3std7windows8registry3KeyZi
setup.obj : error LNK2001: unresolved external symbol 
__D6common12__ModuleInfoZ

build\bin\setup.exe : fatal error LNK1120: 3 unresolved externals
Error: C:\Program Files (x86)\Microsoft Visual 
Studio\2017\BuildTools\VC\Tools\MSVC\14.15.26726\bin\HostX86\x86\link.exe failed with status: 1120


=

But this next one works fine.

=

$ ldc2 "source\setup.d" "source/common.d" -J "build\vars" -of 
"build\bin\setup.exe" -m32 -g


=

I'm using LDC2 version 1.12.0-beta2, on DMD v2.082.0, on Windows 
with VS Build Tools 2017.

Any solutions or corrections appreciated.



Re: Use nested functions as callbacks with Windows API functions?

2018-10-01 Thread spikespaz via Digitalmars-d-learn

On Monday, 1 October 2018 at 21:03:24 UTC, Boris-Barboris wrote:

On Monday, 1 October 2018 at 20:27:43 UTC, spikespaz wrote:
I was hoping I could use something more akin to JavaScript's 
syntax: (void* hWnd, long) => {}.


I tried this but I'm getting errors with the signature, it 
says the function is a delegate and apparently Windows API 
can't accept a delegate.


You can make it a non-delegate by passing a pointer to hWndList 
in lParams as it was supposed to by WinApi devs, instead of 
zero, and not implicitly capturing stack pointer by referencing 
hWndList directly from the body.


https://run.dlang.io/is/t4k4Nc


The problem with the code you have is that the callback needs to 
be extern (Windows). I don't know how to do that with a "lambda".


===

import core.sys.windows.windows: EnumWindows;
import std.stdio: writeln;

void main() {
void*[] hWndList;

EnumWindows((void* hWnd, void* lParam) nothrow {
*(cast(void*[] *) lParam) ~= hWnd;
return true;
}, );

writeln(hWndList);
}

===

source\cb.d(7): Error: function 
core.sys.windows.winuser.EnumWindows(extern (Windows) int 
function(void*, long) nothrow, long) is not callable using 
argument types (bool function(void* hWnd, void* lParam) pure 
nothrow @system, void*[]*)
source\cb.d(7):cannot pass argument __lambda1 of type 
bool function(void* hWnd, void* lParam) pure
nothrow @system to parameter extern (Windows) int function(void*, 
long) nothrow


Re: Use nested functions as callbacks with Windows API functions?

2018-10-01 Thread spikespaz via Digitalmars-d-learn

On Monday, 1 October 2018 at 21:03:24 UTC, Boris-Barboris wrote:

On Monday, 1 October 2018 at 20:27:43 UTC, spikespaz wrote:
I was hoping I could use something more akin to JavaScript's 
syntax: (void* hWnd, long) => {}.


I tried this but I'm getting errors with the signature, it 
says the function is a delegate and apparently Windows API 
can't accept a delegate.


You can make it a non-delegate by passing a pointer to hWndList 
in lParams as it was supposed to by WinApi devs, instead of 
zero, and not implicitly capturing stack pointer by referencing 
hWndList directly from the body.


https://run.dlang.io/is/t4k4Nc


I don't know how to do this. I'm not the best with pointers, I'm 
still learning D and I'm unfamiliar with functional programming.


==

import core.sys.windows.windows: EnumWindows;
import std.stdio: writeln;

extern (Windows) int callback(void* hWnd, long hWndList) nothrow {
hWndList ~= hWnd;

return true;
}

void main() {
void*[] hWndList;

EnumWindows(, );

writeln(hWndList);
}

==

Clearly I can't use  to pass the reference, how would I 
access the variable by the memory address inside the callback?




Use nested functions as callbacks with Windows API functions?

2018-10-01 Thread spikespaz via Digitalmars-d-learn

I have the following code, this works.



import core.sys.windows.windows: EnumWindows;
import std.stdio: writeln;

void*[] hWndList;

extern (Windows) int callback(void* hWnd, long /* lParams */ ) 
nothrow {

hWndList ~= hWnd;

return true;
}

void main() {
EnumWindows(, 0);

writeln(hWndList);
}



I was hoping I could use something more akin to JavaScript's 
syntax: (void* hWnd, long) => {}.


I tried this but I'm getting errors with the signature, it says 
the function is a delegate and apparently Windows API can't 
accept a delegate.




import core.sys.windows.windows: EnumWindows;
import std.stdio: writeln;

void main() {
void*[] hWndList;

EnumWindows((void* hWnd, long /* lParams */ ) nothrow {
hWndList ~= hWnd; return true;
}, 0);

writeln(hWndList);
}



I'm not going to even paste the compiler error because I am very 
clearly going about this the wrong way.


Of course there is nothing wrong with defining each callback as a 
separate function, but then comes the issue of naming them. I 
also don't like the way it makes my code look.


Thanks.


Entry point errors when using LDC to compile Windows Subsystem module with -m32

2018-09-20 Thread spikespaz via Digitalmars-d-learn
I have a user having issues running my project on their 32-bit 
Windows install. I thought LDC2 compiled as 32-bit by default, 
but for some reason the errors persist for him regardless.


In attempt to resolve this, I am doing everything that requires 
32-bit explicitly. I downloaded a known-good 32-bit libcurl.dll 
to distribute with the project, I added -m32 to all of the 
compile commands, added -L/SUBSYSTEM:WINDOWS etc.


When comping with the command below, I get linker errors saying 
that '/SUBSYSTEM:WINDOWS" isn't recognized and is ignored, and 
entry point must be defined. MSVCE linker fails with status 1221.


ldc2 "source/launcher.d" "source/common.d" 
-of="build/$release/launcher.exe" \

-m32 -O3 -ffast-math -release -g -L/SYBSYSTEM:WINDOWS

Compiling with the following command however works fine, but 
doesn't work on 32-bit systems.


ldc2 "source/launcher.d" "source/common.d" 
-of="build/$release/launcher.exe" \

-O3 -ffast-math -release -g

The issue stems from using 'extern (Windows) WinMain' as the 
entry point in the file. Any ideas how I can resolve this?


https://github.com/spikespaz/search-deflector/blob/master/source/launcher.d
https://github.com/spikespaz/search-deflector/blob/master/build.sh


Is it possible to translate this API's C headers?

2018-09-16 Thread spikespaz via Digitalmars-d-learn
There is a project that I wish to use from D 
(https://ultralig.ht).


It's Electron, but with forked WebKit and the samples are very, 
very fast.


This is a great compromise between wanting to have a very custom 
interface and not wanting to use the slow 
Electron/Sciter/Awesomium/WebView.


I am having trouble porting the C headers though. Firstly, I 
barely know C at all, especially not enough to do this. The 
extent of my C knowledge is terminal TicTacToe game I made three 
years ago.


I tried using all of the conversion tools under the "Interfacing 
with C" page of the wiki, but I'm getting import errors. Probably 
because the paths are all using "<>", expecting an include path 
from the compiler. I tried to solve this by refractoring the 
imports to use relative quoted paths.


But even when I fixed that, I kept hitting miscellaneous problems 
with MSVC, LLVM, and every other dependency under the sun those 
conversion tools needed. So I figured that Windows was just a 
crappy ecosystem, and tried it on Linux. No easier.


So now I'm here, a C noob, really wanting to use Adam's great 
project from the D language. The only barrier is my lack of 
knowledge in C. And I definitely do not have the means to port 
these headers by hand.


Could one of you give me pointers about how to go about this? I 
have the dynamic link libraries, the static libraries, and the 
header includes.


https://github.com/ultralight-ux/ultralight
https://github.com/ultralight-ux/ultralight-0.9-api


Re: std.encoding:2554 - Unrecognized Encoding: big5 - Please help!

2018-08-28 Thread spikespaz via Digitalmars-d

On Tuesday, 28 August 2018 at 13:38:39 UTC, spikespaz wrote:
I have a user who submitted a bug report for one of my 
projects. The error is in std\encoding.d on line 2554.


The problem arises when he types 
"google.com.hk/search?q={{query}}" (exact string) into this 
function:

https://github.com/spikespaz/search-deflector/blob/master/source/setup.d#L253-L278

Here is the issue on GH:
https://github.com/spikespaz/search-deflector/issues/12

I really can't figure this one out and any help would be 
appreciated. Thanks.


To add to the parent, I've recompiled with debugging and this is 
the full traceback. As I suspected, it's an error with curl:


0x7FF77A162F4D in std.encoding.EncodingScheme 
std.encoding.EncodingScheme.create(immutable(char)[])
0x7FF77A14300A in 
std.net.curl._decodeContent!char._decodeContent at 
C:\D\ldc2\import\std\net\curl.d(1213)
0x7FF77A143610 in std.net.curl._basicHTTP!char._basicHTTP at 
C:\Users\spike\Documents\github.com\spikespaz\search-deflector\source\common.d(1078)
0x7FF77A142C97 in std.net.curl.get!(std.net.curl.HTTP, 
char).get at 
C:\Users\spike\Documents\github.com\spikespaz\search-deflector\source\common.d(562)
0x7FF77A1411E0 in 
std.net.curl.get!(std.net.curl.AutoProtocol, char).get at 
C:\D\ldc2\import\std\net\curl.d(574)
0x7FF77A146635 in setup.getCustomEngine at 
C:\Users\spike\Documents\github.com\spikespaz\search-deflector\source\setup.d(264)
0x7FF77A145C8E in setup.setup at 
C:\Users\spike\Documents\github.com\spikespaz\search-deflector\source\setup.d(44)
0x7FF77A145AD0 in D main at 
C:\Users\spike\Documents\github.com\spikespaz\search-deflector\source\setup.d(26)
0x7FF77A1AAD8D in void rt.dmain2._d_run_main(int, char**, 
extern (C) int function(char[][])*).runAll()

0x7FF77A1AAC3A in d_run_main
0x7FF77A1C9658 in __scrt_common_main_seh at 
f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl(283)

0x7FFEC50687E4 in BaseThreadInitThunk
0x7FFEC701B311 in RtlUserThreadStart


std.encoding:2554 - Unrecognized Encoding: big5 - Please help!

2018-08-28 Thread spikespaz via Digitalmars-d
I have a user who submitted a bug report for one of my projects. 
The error is in std\encoding.d on line 2554.


The problem arises when he types 
"google.com.hk/search?q={{query}}" (exact string) into this 
function:

https://github.com/spikespaz/search-deflector/blob/master/source/setup.d#L253-L278

Here is the issue on GH:
https://github.com/spikespaz/search-deflector/issues/12

I really can't figure this one out and any help would be 
appreciated. Thanks.


Re: Distribute debug information so I can get informative stack traces?

2018-08-27 Thread spikespaz via Digitalmars-d

On Monday, 27 August 2018 at 22:46:31 UTC, tide wrote:

On Monday, 27 August 2018 at 22:37:53 UTC, spikespaz wrote:
I am compiling my project's executables with `-g`, so it 
outputs `pdb` files. I read that this is necessary to get a 
useful stack trace.


When a user reports an issue, my program gives them a link 
where the issue body is pre-filled with the crash exception 
information.


Example:
https://github.com/spikespaz/search-deflector/issues/10

For some reason though, their reports don't have all of the 
call stack information that I see when I crash during 
development.


How can I make my program give verbose stack traces like 
Python, so I can determine what the issue is when users report 
problems?


Phobos isn't built with debug info. You'd have to build it 
yourself with the debug info and link to that instead.


I am using LDC2, maybe that makes a difference, but I do get 
Phobos debug info on my machine. I should have clarified that it 
just doesn't appear to work on any other machine besides mine.


Is there a better way to do this?


Distribute debug information so I can get informative stack traces?

2018-08-27 Thread spikespaz via Digitalmars-d
I am compiling my project's executables with `-g`, so it outputs 
`pdb` files. I read that this is necessary to get a useful stack 
trace.


When a user reports an issue, my program gives them a link where 
the issue body is pre-filled with the crash exception information.


Example:
https://github.com/spikespaz/search-deflector/issues/10

For some reason though, their reports don't have all of the call 
stack information that I see when I crash during development.


How can I make my program give verbose stack traces like Python, 
so I can determine what the issue is when users report problems?


Re: Trouble with LDC2 and definition file to hide console?

2018-08-20 Thread spikespaz via Digitalmars-d-learn

On Monday, 20 August 2018 at 13:42:58 UTC, spikespaz wrote:
I am trying to add a *.def file to my program to hide the 
console window on launch, as it doesn't need to display 
anything to function. It is a Windows only application.


[...]


Also adding that the linker flag I have stated above also is 
ignored by the linker.


LINK : warning LNK4044: unrecognized option 
'/exet:nt/su:windows'; ignored


Trouble with LDC2 and definition file to hide console?

2018-08-20 Thread spikespaz via Digitalmars-d-learn
I am trying to add a *.def file to my program to hide the console 
window on launch, as it doesn't need to display anything to 
function. It is a Windows only application.


I saw at this post 
(https://forum.dlang.org/post/ilj5vn$ef4$1...@digitalmars.com) that 
I could either use a linker flag, -L/exet:nt/su:windows, or add a 
module definition file. I decided on the definition file.


EXETYPE NT
SUBSYSTEM WINDOWS

I have this file named deflector.def, and I compile with the 
command as follows.


ldc2 source/* -of="build/SearchDeflector-x86.exe" -O3 -ffast-math 
-release



All of my source code and the *.def file is in the source/ 
directory. I am not using DUB. The issue when compiling says that 
those two definitions(?) aren't supported for my target. That 
doesn't make sense because I am using the MSVC linker with LDC2.


source\deflector.def(1) : warning LNK4017: EXETYPE statement not 
supported for the target platform; ignored
source\deflector.def(2) : warning LNK4017: SUBSYSTEM statement 
not supported for the target platform; ignored


Any help would be appreciated.

I would also like to know how to add a PNG or ICO file to my 
compiled executable. I have icons in the resolutions of 16, 32, 
64, 128, 256. Currently I'm adding them in using GitHub's RCEDIT 
tool (https://github.com/electron/rcedit) but I would like a more 
proper way.


Truncate is missing from std.stdio.File, will this do the trick?

2018-07-23 Thread spikespaz via Digitalmars-d
I needed a truncate function on the `std.stdio.File` object, so I 
made this function. Does it look okay? Are there any 
cross-platform improvements you can think of that should be added?



import std.stdio: File;

void truncate(File file, long offset) {
version (Windows) {
import core.sys.windows.windows: SetEndOfFile;

file.seek(offset);
SetEndOfFile(file.windowsHandle());
}

version (Posix) {
import core.sys.posix.unistd: ftruncate;

ftruncate(file.fileno(), offset);
}
}



Linker error for core.sys.windows.winuser imports when compiling as 64 bit.

2018-06-30 Thread spikespaz via Digitalmars-d-learn
Hey guys, I'm getting a linker error when compiling with DMD 
`-m63` that I don't get as 23 bit.


I'm importing `ShowWindow` from `core.sys.windows.winuser`, and I 
get the following:


C:\D\dmd2\windows\bin\lld-link.exe: warning: main.obj: undefined 
symbol: ShowWindow

error: link failed
Error: linker exited with status 1

My compiler command is `dmd main.d -m64 -i -O -release -inline 
-boundscheck=off

`.

I don't think the source code would make a difference other than 
to say that I'm calling `ShowWindow`.


Any help would be much appreciated. Thanks!

Also, how does formatting work? Markdown doesn't seem to work, or 
HTML.