Help: running a method from the importing file's method "space"

Regan Heath regan at netmail.co.nz
Tue May 1 10:34:23 PDT 2012


I'm not sure if any of this is helpful but I've had a tinker and had some
measure of success :p

I think you have the following issues to resolve:
1. When you build the lib, you need to tell it that the progMain symbol is
to be found 'extern'ally.
2. When you build the exe, you have to make sure the linker goes looking
for WinMain and not main /and/ that it looks in the lib for it.

I've managed to get something "working" but it's not what you want (but it
might help you get there) and it's not pretty...

1. Add the following line to mylib.d:
             extern(C) int progMain();

             This tells dmd that when it compiles mylib.d the symbol  
progMain
is
to
be found externally, and it's C linkage (I tried D linkage, but this
prepends "MyLib" to the symbol it searches for).

2. Modify test.d and make it read:
             extern(C)
             void progMain() {

             This makes progMain a C linkage symbol, which the linker will
find
and
use.

3. Compile mylib.d with:
              dmd -c mylib

             (I know, this doesn't build a lib more on that later..)

4. Compile test.d with:
              dmd -c test

5. Run link.exe manually, e.g.

             <path to dmd bin>\link.exe
test+mylib,,nul,phobos+user32+kernel32/noi;

             This produces a test.exe which runs and executes progMain from
test.d.


Initially I was trying to get it working with a lib but I got dead-ended.

Using the code changes I mentioned above, and a test.def which reads:
             EXETYPE NT
             SUBSYSTEM WINDOWS

If you go:

             dmd -lib mylib
             dmd -c test
             link.exe test,,nul,mylib+phobos+user32+kernel32/noi,test.def;

you get:

             OPTLINK : Warning 134: No Start Address

I think that the reason for this is that test.obj does not define an entry
point, see:
             http://www.digitalmars.com/ctg/OptlinkErrorMessages.html
             (No Start Address)

This implies it is looking for entry points in object files, and perhaps
that means /not/ libs??  Not sure.


So, I tried to re-use my earlier extern trick adding:

extern(Windows)
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nCmdShow);

to test.d, but that gave the same results.


References..
http://dlang.org/windows.html
http://www.digitalmars.com/ctg/optlink.html
https://github.com/AndrejMitrovic/DWinProgramming

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


More information about the Digitalmars-d-learn mailing list