Number overflow?<div>So I implemented the suggested changes (you can check them out at <a href="http://dl.dropbox.com/u/15024434/version2.zip">http://dl.dropbox.com/u/15024434/version2.zip</a>)</div><div>But now I get when I compile it : <br>
"kernel32.def(738) : Error 12: Number Overflow: (strange symbol over here)"</div><div><br></div><div>I do agree I should've picked a simpler example but I think the statisfaction will be even bigger if I were to succeed :p</div>
<div><br><div class="gmail_quote">2011/5/1 maarten van damme <span dir="ltr"><<a href="mailto:maartenvd1994@gmail.com">maartenvd1994@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Wow, thanks for the help<div>The first thing I did was in the .di file adding extern(windows){ ... }</div><div>and now compiling doesn't give errors and when examining with dllexp I can see that it exports the same functions as the real kernel32.dll :D</div>

<div><br></div><div>Now I'm going to implement all other suggested changes, thanks a lot<div><div></div><div class="h5"><br><br><div class="gmail_quote">2011/4/30 Rainer Schuetze <span dir="ltr"><<a href="mailto:r.sagitario@gmx.de" target="_blank">r.sagitario@gmx.de</a>></span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'm not sure your wrapping will work with kernel32.dll, but in general here are a few tips:<br>
<br>
- most functions in the windows API use the __stdcall calling convention in C/C++, which translates to D as "extern(Windows)"<br>
<br>
- this will usually add the number of bytes passed on the stack as a "@NN" postfix to the function name. This postfix does not exist in kernel32.dll, but in the import library kernel32.lib that you find in the dmd lib folder. Maybe you can use the standard import library, or use the translation shown below.<br>


<br>
- as the exported function and the function you want to chain to have identical names, you have to change at least one of these and modify them in some build step. I'd suggest to do this in the def file:<br>
<br>
The symbols in the d-source file containing:<br>
<br>
----<br>
extern(Windows) HANDLE imported_GetCurrentProcess();<br>
<br>
export extern(Windows) HANDLE internal_GetCurrentProcess()<br>
{<br>
  return imported_GetCurrentProcess();<br>
}<br>
----<br>
<br>
can be mapped to other symbols in the def file:<br>
<br>
----<br>
EXPORTS<br>
  GetCurrentProcess = internal_GetCurrentProcess<br>
<br>
IMPORTS<br>
  imported_GetCurrentProcess = kernel33.GetCurrentProcess<br>
----<br>
<br>
- if you don't know the number of arguments, you should not call the wrapped function, as this will change the callstack. Instead, you should just jump to it:<br>
<br>
void internal_hread()<br>
{<br>
  asm<br>
  {<br>
    naked;<br>
    jmp imported_hread;<br>
  }<br>
}<br>
<br>
I haven't tried all that, though, so there might be some mistakes...<br><font color="#888888">
<br>
Rainer</font><div><div></div><div><br>
<br>
<br>
Denis Koroskin wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Sat, 30 Apr 2011 13:47:53 +0400, maarten van damme <<a href="mailto:maartenvd1994@gmail.com" target="_blank">maartenvd1994@gmail.com</a>> wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I've changed this, I think I'm still kinda confused with lib files. They've<br>
told me you can't do something with them without a .di file<br>
So I went ahead and made a kernel33.di file. I now import it in kernel32.d<br>
and my declaration is<br>
System(C){<br>
export void * exportedfunctionblablabal(){<br>
   return exportedfunctionblablablal();<br>
}<br>
...<br>
}<br>
<br>
The file in the directory are:<br>
kernel32.d : <a href="http://dl.dropbox.com/u/15024434/d/kernel32.d" target="_blank">http://dl.dropbox.com/u/15024434/d/kernel32.d</a><br>
kernel33.di : <a href="http://dl.dropbox.com/u/15024434/d/kernel33.di" target="_blank">http://dl.dropbox.com/u/15024434/d/kernel33.di</a><br>
kernel33.lib : <a href="http://dl.dropbox.com/u/15024434/d/kernel33.lib" target="_blank">http://dl.dropbox.com/u/15024434/d/kernel33.lib</a><br>
kernel33.dll : <a href="http://dl.dropbox.com/u/15024434/d/kernel33.dll" target="_blank">http://dl.dropbox.com/u/15024434/d/kernel33.dll</a><br>
<br>
I've tried to compile using dmd -d kernel32.d kernel33.di kernel33.lib but<br>
it throws errors like<br>
"Error 42: Symbol undifined _Dkernel1336_hreadfzpV"<br>
I have literally no clue why this is the case, can someone help me out or<br>
look at the files?<br>
<br>
2011/4/27 maarten van damme <<a href="mailto:maartenvd1994@gmail.com" target="_blank">maartenvd1994@gmail.com</a>><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I'm afraid I've been a little unclear.<br>
I've copied kernel32.dll from the windows dir, renamed it to kernel33.dll<br>
and generated a .lib from it using implib.<br>
Then I've created a d file with a correct dllmain(stolen from examples) and<br>
between<br>
<br>
system(C){<br>
export void * exportedfunctionfromkernel33.dll();<br>
export void * exportedfunction2fromkernel33.dll();<br>
...<br>
}<br>
<br>
But it looks like you can't both declare a function from another lib and<br>
export it at the same time.<br>
<br>
</blockquote></blockquote>
<br>
In your kernel33.di, try making it extern (C) export void* _hread(); etc. You functions get D mangling otherwise.<br>
<br>
I'd also suggest you to start with a less complex example, e.g. export only one function, make sure it works, then add the rest.<br>
<br>
If you think your .lib files doesn't do its job, try using .def file instead. I find them extremely helpful, and they are a lot easier to edit/extend.<br>
<br>
Hope that helps.<br>
</blockquote>
</div></div></blockquote></div><br></div></div></div>
</blockquote></div><br></div>