Sinatr
Sinatr

Reputation: 21989

Using _stdcall will change name of exported functions in dll

I am trying to make module (dll) for Profilab. For that to work, there should be a list of exported names, to example

// return number of inputs
unsigned char NumInputs()

when looking at examples for C++ Builder, it's declared like this

extern "C" __declspec(dllexport) unsigned char _stdcall NumInputs();

when I declare it same way in Visual Studio 2013 Express (?) C++ project, I am getting name exported like this (checked with dependency walker):

_NumInputs@0

Which doesn't works for Profilab.

Removing _stdcall part will generate proper name (NumImputs), but software will crash and I think is due to missing _stdcall part.

What should I do? How to export NumInputs and have _stdcall at same time?

Upvotes: 0

Views: 517

Answers (1)

Deduplicator
Deduplicator

Reputation: 45654

Define the function with the right calling convention (stdcall).

Thus, you won't get a crash.

Still, you also need the right names or it won't link, so use a def-file which explicitly lists which function shall be exported using what name (if any) and/or specified ordinal.

LIBRARY   BTREE
EXPORTS
   Insert   @1
   Delete   @2
   Member   @3
   Min   @4

This example was copied from the linked documentation. All the export statements follow this pattern:

entryname[=internalname] [@ordinal [NONAME]] [[PRIVATE] | [DATA]]

Upvotes: 1

Related Questions