# Create DLL for other languages

**URL:** <https://clarionhub.com/t/create-dll-for-other-languages/2614>\
**Category:** questions\
**Tags:** interop, dll\
**Created:** [May 14, 2019, 7:59am UTC](https://clarionhub.com/t/create-dll-for-other-languages/2614 "2019-05-14T07:59:47Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![TonyLam](https://clarionhub.com/user_avatar/clarionhub.com/tonylam/32/6185_2.png) [@TonyLam](https://clarionhub.com/u/TonyLam)\
**Post date:** [May 14, 2019, 7:59am UTC](https://clarionhub.com/t/create-dll-for-other-languages/2614/1 "2019-05-14T07:59:47Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![Mike\_Duglas](https://clarionhub.com/user_avatar/clarionhub.com/mike_duglas/32/1061_2.png) [@Mike\_Duglas](https://clarionhub.com/u/Mike_Duglas)\
**Post date:** [May 14, 2019, 8:48am UTC](https://clarionhub.com/t/create-dll-for-other-languages/2614/2 "2019-05-14T08:48:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Constantine](https://clarionhub.com/letter_avatar_proxy/v4/letter/c/3bc359/32.png) [@Constantine](https://clarionhub.com/u/Constantine)\
**Post date:** [May 14, 2019, 8:57am UTC](https://clarionhub.com/t/create-dll-for-other-languages/2614/3 "2019-05-14T08:57:06Z")

</div>

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… 🙂  
I agree with Mike\_Duglas: this is not so simple…

---

<div class="post-metadata">

**Author:** ![jslarve](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@jslarve](https://clarionhub.com/u/jslarve)\
**Post date:** [May 15, 2019, 4:19pm UTC](https://clarionhub.com/t/create-dll-for-other-languages/2614/4 "2019-05-15T16:19:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TonyLam](https://clarionhub.com/user_avatar/clarionhub.com/tonylam/32/6185_2.png) [@TonyLam](https://clarionhub.com/u/TonyLam)\
**Post date:** [May 17, 2019, 2:28am UTC](https://clarionhub.com/t/create-dll-for-other-languages/2614/5 "2019-05-17T02:28:52Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![jslarve](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@jslarve](https://clarionhub.com/u/jslarve)\
**Post date:** [May 17, 2019, 3:36am UTC](https://clarionhub.com/t/create-dll-for-other-languages/2614/6 "2019-05-17T03:36:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Reginald\_van\_Niekerk](https://clarionhub.com/user_avatar/clarionhub.com/reginald_van_niekerk/32/1850_2.png) [@Reginald\_van\_Niekerk](https://clarionhub.com/u/Reginald_van_Niekerk)\
**Post date:** [January 26, 2022, 5:48pm UTC](https://clarionhub.com/t/create-dll-for-other-languages/2614/7 "2022-01-26T17:48:35Z")

</div>

Hi

Apologies for opening this old discussion, but this is something we have started pursuing recently.

We are developing new frontends in C# but most of our business logic is in Clarion.

We have had some success with the following procedures:  
AddNumbers(long Num1, long Num2), long, C, name(‘AddNumbers’)  
AddNumbersV2(\*long pNum1, \*long pNum2), long, C, name(‘AddNumbersV2’)  
TestStringV1(BSTRING pStrA,BSTRING pStrB),BSTRING,C,name(‘TestStringV1’)  
TestStringV2(\*BSTRING pStrA,\*BSTRING pStrB),BSTRING,C,name(‘TestStringV2’)

Passing QUEUE and GROUP structures seems significantly more challenging eg.  
TestGroupV1(\*mGroup1 pGroup)ULONG,C,name(‘TestGroupV1’)  
TestQueueV1(\*mQueue1 pQueue)ULONG,C,name(‘TestQueueV1’)

My question therefore is whether passing these structures is at all possible from Clarion to eg. C#?

Regards

Reggie

---

<div class="post-metadata">

**Author:** ![jslarve](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@jslarve](https://clarionhub.com/u/jslarve)\
**Post date:** [January 26, 2022, 6:07pm UTC](https://clarionhub.com/t/create-dll-for-other-languages/2614/8 "2022-01-26T18:07:55Z")

</div>

Have you tried (LONG pAddress)?

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [January 26, 2022, 9:12pm UTC](https://clarionhub.com/t/create-dll-for-other-languages/2614/9 "2022-01-26T21:12:53Z")

</div>

If you are passing \*Group I think you want RAW on the prototype or the compiler will also pass the Size as an extra Long parameter.

You probably want to pass the size yourself as a parameter so your function can verify the Struct is the size it is expecting or larger. You see this very often on Windows API calls.

The Queue internals are not published so I doubt you can pass a queue in any easy way. You could make a big array and pass that. Maybe load it into a memory mapped file if that’s something that .Net can access easily.

---

<div class="post-metadata">

**Author:** ![jslarve](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@jslarve](https://clarionhub.com/u/jslarve)\
**Post date:** [January 26, 2022, 11:12pm UTC](https://clarionhub.com/t/create-dll-for-other-languages/2614/10 "2022-01-26T23:12:02Z")

</div>

Might as well be json.

---

<div class="post-metadata">

**Author:** ![MarkGoldberg](https://clarionhub.com/user_avatar/clarionhub.com/markgoldberg/32/1511_2.png) [@MarkGoldberg](https://clarionhub.com/u/MarkGoldberg)\
**Post date:** [January 27, 2022, 12:55pm UTC](https://clarionhub.com/t/create-dll-for-other-languages/2614/11 "2022-01-27T12:55:41Z")

</div>

see [Using Groups with .Net Com Controls Part 1 - code / Interop - ClarionHub](https://clarionhub.com/t/using-groups-with-net-com-controls-part-1/311)

Notice the [StructLayout(LayoutKind.Sequential, Pack = 1)] attribute on the struct

My approach to sending Queues from CW to C#  
In Clarion: Serialize to json & put into a MemoryMappedFile (MMF) (using APIs)  
Then I RUN my C# EXE  
In C#: I read the contents using System.Io.MemoryMappedFiles and a StreamReader  
then deserialize using NewtonSoft Json

I used a MMF because I was loading data then RUN()'ing the C# .EXE  
For a direct call, I imagine it would be far easier to pass the data as a BSTRING

BTW, this is an interesting subject to many, and seems like it deserves it’s own appropriately titled thread.
