Create DLL for other languages


#1

Hi all,

I have some DLLs generated by C10. They work perfectly fine when called from other Clarion programs. However, if I call the same DLLs from NodeJS, they don’t seem to work, the calling program shuts down. Any idea?

My clarion app:

MAP
tester(STRING, LONG),BYTE,NAME(‘tester’)
END

tester FUNCTION(inString, inLong)

ReturnValue BYTE(1)

CODE

message('Inside DLL: ' & inString & ' / ' & inLong)

RETURN ReturnValue

#2

This is not so simple. At least your export function must have explicit calling convention C or PASCAL.
STRING type is not a good choice for parameters, use (*CSTRING) instead.
Also I suspect that Clarion runtime should be linked to the dll or be placed in same folder.
Also read AttachThreadToClarion topic in the help.


#3

Pascal calling convention is preffered (because Windows API uses it).
Also you must avoid cross-calling, for example Clarion - NodeJS - Clarion or NodeJs Clarion - NodeJS. And a lot of other things… :slight_smile:
I agree with Mike_Duglas: this is not so simple…


#4

Should also use the NAME attribute to get around name mangling.


#5

Thanks all for your hints, I figured it out now.

MAP
proc_name(LONG),C,NAME(‘proc_name’) !accepting the address of a cString from other programs
END

proc_name PROCEDURE(adr_CString)

myStr &CSTRING

CODE
mystr &= (adr_CString)


#6

If you add a parameter for the length, you can do something like this:

mystr &= (adr_CString) & ‘:’ & Length

Otherwise, you can run into trouble on some functions.