PostgreSQL - Calling Clarion Function from a PSQL Function / Trigger

Has anyone created a CW DLL that can be called from PostgreSQL to do some actions?

We have some complicated calculations and encryption we need to do and we don’t want to rewrite our base code at this time.

Thanks for any examples.

I haven’t done it. I don’t think a clarion dll could be called directly because I think the clarion dll is a little different to std windows.
But it should be possible to create a C windows Dll that calls into a clarion one.

That will be quicker than translating the C into Clarion.

@KevinErskine if you do fancy having a go at translating it from C to Clarion

You’ll be using the C instead of typical Pascal for the calling convention,

so the
pass by value, fixed-length = someproc (Datatypes)
pass by reference, fixed-length = someproc (long) where long is the address to the datatype
pass by reference, variable-length = someproc (long) where long is the address to the datatype
or you could use *[DataType] where asterisk is the address (long) to the [DataType].

The other thing to watch out for is when you need to use RAW. Raw removes the length of strings, groups and ? (any’s).

I couldnt find any source code that refers to these C functions, only snippets at that webpage, but you have the Topspeed C & C++ compiler built into Clarion, so maybe find some small postgres source code and see if you can get that compiling in clarion.

Some of the questions you might encounter can probably be found on here, like
How can a C typedef stucture containing an array be converted to a clarion structure? - questions - ClarionHub

Linking C C++

You’ll just have to hunt around a bit, but I’d start with finding the postgres source code you want to compile or translate, or better still see if they have supplied any dll’s that you want to use, and then just make a lib file using the libmaker and then define some api’s in your code.

1 Like

Hi Kevin

I don’t have an answer, however, if PG is 64 bit then could it even call into a 32 bit dll ?

Mark

Thats a good point! They cant.
Process Interoperability - Win32 apps | Microsoft Learn

On 64-bit Windows, a 64-bit process cannot load a 32-bit dynamic-link library (DLL). Additionally, a 32-bit process cannot load a 64-bit DLL. However, 64-bit Windows supports remote procedure calls (RPC) between 64-bit and 32-bit processes (both on the same computer and across computers). On 64-bit Windows, an out-of-process 32-bit COM server can communicate with a 64-bit client, and an out-of-process 64-bit COM server can communicate with a 32-bit client. Therefore, if you have a 32-bit DLL that is not COM-aware, you can wrap it in an out-of-process COM server and use COM to marshal calls to and from a 64-bit process.

DLLImport is classed as in-process, so wouldnt meet the out of process requirement mentioned above.

dllexport, dllimport | Microsoft Learn

1 Like