Can't use a C++ class from a DLL

Gor Gyolchanyan gor.f.gyolchanyan at gmail.com
Mon Oct 29 07:01:45 PDT 2012


It will be fine for Windows, because in Window long and unsigned long are
always 4 byte. But other systems (for instance, all Linux distros) have
long and unsigned long 8 bytes under 64-bit systems. c_ulong makes sure,
that it's the correct size on all systems.

On Mon, Oct 29, 2012 at 5:55 PM, Artie <apple2000 at mail.ru> wrote:

>
>> As all your functions are `APIENTRY`, write `extern(Windows):` before
>> them. And use `c_ulong` as analogue of `unsigned long`. So full correct
>> `IBank` interface declaration here:
>> ---
>> import core.stdc.config: c_ulong;
>>
>> extern(C++) interface IBank
>> {
>> extern(Windows):
>>     const char* getLastError();
>>     const char* getDetail(char* detail);
>>     bool deposit(c_ulong number, double amount);
>>     bool withdraw(c_ulong number, double amount);
>>     double getBalance(c_ulong number);
>>     bool transfer(c_ulong numberFrom, IBank* bankTo, c_ulong numberTo,
>> double amount);
>>     bool transferAccept(IBank* bankFrom, c_ulong numberTo, double amount);
>> };
>> ---
>>
>
> Thank you very much, Denis. It was quite confusing to mix extern(C++) and
> extern(Windows). And I also thank Jakob for syntax specification.
>
> BTW, it's said in the ABI reference that `unsigned long` must be
> substituted with `uint`. And it seems to work fine for the data I used in
> the example.
>



-- 
Bye,
Gor Gyolchanyan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20121029/d53151ac/attachment.html>


More information about the Digitalmars-d mailing list