Page 1 of 1

[DLL] Exporting a Function with a decorated name

Posted: Fri May 04, 2018 9:29 am
by Losee
Hi all,

is it possible to export function in a PureBasic DLL with a decorated name?

In C++ you could export EnableProductSupport as:

Code: Select all

C++:         void __cdecl product::common::EnableProductSupport(void)
undecorated: ?EnableProductSupport@common@product@@YAXXZ
If I wanted to export that in my PureBasic DLL, how could I do that?

Thank you very much!

Re: [DLL] Exporting a Function with a decorated name

Posted: Fri May 04, 2018 9:35 am
by RSBasic
Do you mean ProcedureDLL or ProcedureCDLL? http://www.purearea.net/pb/english/manu ... e/dll.html

Re: [DLL] Exporting a Function with a decorated name

Posted: Fri May 04, 2018 9:41 am
by Losee
The calling convention is not really the problem. It could either be stdcall or cdecl.

My trouble is defining the function name to reflect the C++ representation to be able to decorate it accordingly.

Code: Select all

  ProcedureCDLL product::common::EnableProductSupport()
    ; perform some magic ...
  EndProcedure

Re: [DLL] Exporting a Function with a decorated name

Posted: Fri May 04, 2018 2:41 pm
by skywalk
How is this not handled with header files?

Code: Select all

extern "C" {
  #include "myPBdll.h" //a C header, so wrap it in extern "C" 
}

Re: [DLL] Exporting a Function with a decorated name

Posted: Fri May 04, 2018 3:00 pm
by Losee
@Skywalk:
What do you mean by "not handled"?

To interoperate with another application I need to create a DLL that exports the described functionname. I cannot change the name and I don't know how to export decorated names with PureBasic, that's why I asked.

Re: [DLL] Exporting a Function with a decorated name

Posted: Fri May 04, 2018 3:03 pm
by Fred
I don't think you can do that, it's a C++ mangling and PB doesn't support support this when creating a DLL. The closer I could think of is to create a thin wrapper in C++ (another DLL) which will call your DLL.

Re: [DLL] Exporting a Function with a decorated name

Posted: Fri May 04, 2018 3:54 pm
by skywalk
Losee wrote:@Skywalk:
What do you mean by "not handled"?

To interoperate with another application I need to create a DLL that exports the described functionname. I cannot change the name and I don't know how to export decorated names with PureBasic, that's why I asked.
The C++ application needs to be recompiled with the appropriate header information to call a C or PB function. If you are saying the C++ application cannot be recompiled, then you have to use other means of interprocess communication like the Clipboard or SendMessage(hwDispatch, WM_COPYDATA, hWnd, &MyCDS).

Re: [DLL] Exporting a Function with a decorated name

Posted: Fri May 04, 2018 3:57 pm
by Losee
OK, that's what I thought. My workaround at the moment was to compile my DLL and then use "CFF Explorer" to manually change the Function name to reflect that of the decorated function.

Thanks again.