Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2024-03

opening a serial port in a dll called from dot net fails

4 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Luca Olivetti

I'm writing a dll that is used by a dot net application (32bits).

If I call SerOpen in the initialization section of the dll there is no problem, but if I call it from one of the exported functions it gives me an access denied (GetLastError gives me a 5), and I really need to call it from a function (due to some quirks in the calling program which is not under my control).

A search in the usual places tells me that in dot net opening a serial port with CreateFile (which is what SerOpen does) is forbidden, that you should use the SerialPort class (which I don't think I can do from my dll written in freepascal).

Is there any way to solve my problem?

Bye

Luca

Reply by email

Luca Olivetti
to Luca Olivetti

El 9/3/24 a les 16:24, Luca Olivetti via fpc-pascal ha escrit:

Never mind, I put the serial port access in a separate exe and the dll communicates with it via an udp socket.
I'd still like to know why I got an access denied when trying to open the port from an exported procedure, typical ms bullshit or another case of pebkac?

Bye

Show quoted text 16 lines
I'm writing a dll that is used by a dot net application (32bits). If I call SerOpen in the initialization section of the dll there is no problem, but if I call it from one of the exported functions it gives me an access denied (GetLastError gives me a 5), and I really need to call it from a function (due to some quirks in the calling program which is not under my control). A search in the usual places tells me that in dot net opening a serial port with CreateFile (which is what SerOpen does) is forbidden, that you should use the SerialPort class (which I don't think I can do from my dll written in freepascal). Is there any way to solve my problem? Bye

Reply by email

Elmar Haneke
to Luca Olivetti: I'm writing a dll that is used by a dot net application (32bits). If I call SerOpen in…

Presumably the problem is caused by calling your function from a different thread.

Perhaps it is a solution to put the SerOpen in a thread created by FPC and signal that thread from your dot-net-called function.

Luca Olivetti wrote 16 lines
I'm writing a dll that is used by a dot net application (32bits). If I call SerOpen in the initialization section of the dll there is no problem, but if I call it from one of the exported functions it gives me an access denied (GetLastError gives me a 5), and I really need to call it from a function (due to some quirks in the calling program which is not under my control). A search in the usual places tells me that in dot net opening a serial port with CreateFile (which is what SerOpen does) is forbidden, that you should use the SerialPort class (which I don't think I can do from my dll written in freepascal). Is there any way to solve my problem? Bye

Reply by email

Luca Olivetti
to Elmar Haneke

El 11/3/24 a les 11:38, Elmar Haneke via fpc-pascal ha escrit:

Show quoted text 6 lines
Presumably the problem is caused by calling your function from a different thread. Perhaps it is a solution to put the SerOpen in a thread created by FPC and signal that thread from your dot-net-called function.

Nope, I tried, same error.

Show quoted text 15 lines
Am 09.03.24 um 16:24 schrieb Luca Olivetti via fpc-pascal: > I'm writing a dll that is used by a dot net application (32bits). > > If I call SerOpen in the initialization section of the dll there is no > problem, but if I call it from one of the exported functions it gives > me an access denied (GetLastError gives me a 5), and I really need to > call it from a function (due to some quirks in the calling program > which is not under my control). > > A search in the usual places tells me that in dot net opening a serial > port with CreateFile (which is what SerOpen does) is forbidden, that > you should use the SerialPort class (which I don't think I can do from > my dll written in freepascal). > > Is there any way to solve my problem?

Reply by email