Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.clipper.visual-objects > #9386 > unrolled thread
| Started by | Alexander Schmitt <alexander.schmitt@paidosoft.de> |
|---|---|
| First post | 2016-05-31 03:52 -0700 |
| Last post | 2016-06-20 12:35 +0200 |
| Articles | 20 on this page of 23 — 5 participants |
Back to article view | Back to comp.lang.clipper.visual-objects
How to integrate C DLL into VO and generate interface code Alexander Schmitt <alexander.schmitt@paidosoft.de> - 2016-05-31 03:52 -0700
Re: How to integrate C DLL into VO and generate interface code "Wolfgang Riedmann" <wriedmann@gmail.com> - 2016-05-31 16:11 +0200
Re: How to integrate C DLL into VO and generate interface code "Karl-Heinz" <invalid@invalid.invalid> - 2016-05-31 16:07 +0200
Re: How to integrate C DLL into VO and generate interface code alexander.schmitt@paidosoft.de - 2016-06-01 02:13 -0700
Re: How to integrate C DLL into VO and generate interface code "Wolfgang Riedmann" <wriedmann@gmail.com> - 2016-06-01 12:36 +0200
Re: How to integrate C DLL into VO and generate interface code "Karl-Heinz" <invalid@invalid.invalid> - 2016-06-01 12:37 +0200
Re: How to integrate C DLL into VO and generate interface code alexander.schmitt@paidosoft.de - 2016-06-14 14:05 -0700
Re: How to integrate C DLL into VO and generate interface code "Wolfgang Riedmann" <wriedmann@gmail.com> - 2016-06-15 08:59 +0200
Re: How to integrate C DLL into VO and generate interface code "Karl-Heinz" <invalid@invalid.invalid> - 2016-06-15 09:40 +0200
Re: How to integrate C DLL into VO and generate interface code "Gerhard Bunzel" <g.bunzel@domonet.de> - 2016-06-15 14:34 +0200
Re: How to integrate C DLL into VO and generate interface code alexander.schmitt@paidosoft.de - 2016-06-15 14:06 -0700
Re: How to integrate C DLL into VO and generate interface code "Wolfgang Riedmann" <wriedmann@gmail.com> - 2016-06-16 05:56 +0200
Re: How to integrate C DLL into VO and generate interface code "Wolfgang Riedmann" <wriedmann@gmail.com> - 2016-06-16 06:03 +0200
Re: How to integrate C DLL into VO and generate interface code alexander.schmitt@paidosoft.de - 2016-06-16 14:28 -0700
Re: How to integrate C DLL into VO and generate interface code alexander.schmitt@paidosoft.de - 2016-06-19 13:23 -0700
Re: How to integrate C DLL into VO and generate interface code "Wolfgang Riedmann" <wriedmann@gmail.com> - 2016-06-20 07:29 +0200
Re: How to integrate C DLL into VO and generate interface code "Wolfgang Riedmann" <wriedmann@gmail.com> - 2016-06-21 06:21 +0200
Re: How to integrate C DLL into VO and generate interface code alexander.schmitt@paidosoft.de - 2016-06-22 12:37 -0700
Re: How to integrate C DLL into VO and generate interface code "Wolfgang Riedmann" <wriedmann@gmail.com> - 2016-06-23 04:05 +0200
Re: How to integrate C DLL into VO and generate interface code alexander.schmitt@paidosoft.de - 2016-07-03 13:53 -0700
Re: How to integrate C DLL into VO and generate interface code "Karl-Heinz" <invalid@invalid.invalid> - 2016-07-05 21:19 +0200
Re: How to integrate C DLL into VO and generate interface code "Wolfgang Riedmann" <wriedmann@gmail.com> - 2016-06-20 09:16 +0200
Re: How to integrate C DLL into VO and generate interface code "Karl-Heinz" <invalid@invalid.invalid> - 2016-06-20 12:35 +0200
Page 1 of 2 [1] 2 Next page →
| From | Alexander Schmitt <alexander.schmitt@paidosoft.de> |
|---|---|
| Date | 2016-05-31 03:52 -0700 |
| Subject | How to integrate C DLL into VO and generate interface code |
| Message-ID | <66abaae4-be73-486e-a8d8-b44d0592b744@googlegroups.com> |
Hi there, I want to integrate a DLL (written in C) from a hardware supplier into my VO 2.8 code and could not find relevant information in the group. Or did not know where to search. I have a C-header file that provides information about the functions plus the DLL. The DLL is obviously not an automation server, so Automation Server interface generation from VO would not work. If I take a look into e.g. lib zip from Fabrice Foray, there is an interface defined, e.g. _DLL FUNCTION GetZipDllVersion() AS DWORD PASCAL:ZIPDLL.GetZipDllVersion Is there a way to automatically generate such interface code in VO? Or would I rather guess and write manually? Best, Alex
[toc] | [next] | [standalone]
| From | "Wolfgang Riedmann" <wriedmann@gmail.com> |
|---|---|
| Date | 2016-05-31 16:11 +0200 |
| Message-ID | <dr5kdhF736eU1@mid.individual.net> |
| In reply to | #9386 |
Hi Alex, > I want to integrate a DLL (written in C) from a hardware supplier > into my VO 2.8 code and could not find relevant information in the > group. Or did not know where to search. > > I have a C-header file that provides information about the functions > plus the DLL. > > The DLL is obviously not an automation server, so Automation Server > interface generation from VO would not work. > > If I take a look into e.g. lib zip from Fabrice Foray, there is an > interface defined, e.g. _DLL FUNCTION GetZipDllVersion() AS DWORD > PASCAL:ZIPDLL.GetZipDllVersion > > Is there a way to automatically generate such interface code in VO? > Or would I rather guess and write manually? unfortunately there is no automated way to do this - and guessing is bad, you should know how this need to be implemented. I have done such things several times - if you show maybe a part of the header file and give us the name of the DLL, maybe we can help a little bit. It depends how many functions you have to implement - but of course it is a precise work. And since it is a C DLL, maybe you have also structures and defines to translate.... But the way you have seen in Fabrices zip lip is the correct one. This is a sample: C header file: char * __stdcall zGetFileName(int i); VO interface: _dll function _zGetFileName( nItem as int ) as byte ptr pascal:bszip.dll.zGetFileName Wolfgang --
[toc] | [prev] | [next] | [standalone]
| From | "Karl-Heinz" <invalid@invalid.invalid> |
|---|---|
| Date | 2016-05-31 16:07 +0200 |
| Message-ID | <dr5ku4F76t8U1@mid.individual.net> |
| In reply to | #9386 |
Hi Alex,
>
> Is there a way to automatically generate such interface code in VO?
>
No, but depending on the complexity and number of functions to import, it´s
commonly not that hard to do it manually.
Some pitfalls when you declare a interface to a foreign DLL:
1. UNICODE or ANSI Functions to import ?
2. You may never use VO dynamic Datatypes like STRING, ARRAY,FLOAT etc.
3. Instead of STRINGs always use PSZs
4. Instead of FLOATs always use the Datatype REAL4 or REAL8.
(There is something special to do when a Importfunction returns a
C-float or double)
5. The Functionnames to import are always case-sensitive !
e.g.
_DLL FUNCTION GetZipDllVersion() AS DWORD PASCAL:ZIPDLL.GetZipDllVersion
changed to
_DLL FUNCTION GetZipDllVersion() AS DWORD PASCAL:ZIPDLL.GETZIPDLLVERSION
would throw at startup an ErrorBox like "GETZIPDLLVERSION() not found" .
Regards
Karl-Heinz
BTW. Seems your hometown is "Sindelfingen" ?
I´m living in "Tamm" ;-)
[toc] | [prev] | [next] | [standalone]
| From | alexander.schmitt@paidosoft.de |
|---|---|
| Date | 2016-06-01 02:13 -0700 |
| Message-ID | <7de24866-5bfe-439f-befb-099a84afe0d0@googlegroups.com> |
| In reply to | #9386 |
Hi Karl-Heinz, Wolfgang,
Thanks for your great hints.
That points me into the right direction! Luckily, there are only a couple of simple functions and a structure to interface an RFID reader.
Here an excerpt:
C-Header:
#define RFID_API __declspec(dllexport)
struct RFID_API TRPINFO
{
bool isUserCard;
int numberOfParts;
char *uID;
};
My VO-Interface:
STRUCTURE RFID_API
MEMBER isUserCard as LOGIC
MEMBER numberOfParts as DWORD
MEMBER uID as psz
C:
RFID_API int OpenReader(char* readerport);
VO:
_dll FUNCTION OpenReader(pszReaderPort as PSZ) as DWORD PASCAL:RFIDDLL.OpenReader
C:
RFID_API int GetItem(int trpNr, TRPINFO* pTrpInfo);
VO:
_dll FUNCTION GetItem(trpNr as DWORD, pTrpInfo as PTR) as DWORD PASCAL:RFIDDLL.GetItem
C:
RFID_API void GetErrorMessage(int nErrorCode, char* pMessage, int nLength);
VO:
_dll FUNCTION GetErrorMessage(nErrorCode as DWORD, pMessage as PSZ, nLength AS DWORD) as VOID PASCAL:RFIDDLL.GetErrorMessage
I get back to you once I have implemented and tested (currently waiting for the reader still)
And, yes, I am from Sindelfingen. Small VO-world ;-) Greetings to Tamm :-)
Best,
Alex
[toc] | [prev] | [next] | [standalone]
| From | "Wolfgang Riedmann" <wriedmann@gmail.com> |
|---|---|
| Date | 2016-06-01 12:36 +0200 |
| Message-ID | <dr7s4pFkoh2U1@mid.individual.net> |
| In reply to | #9391 |
Hi Alex, for the structures you have to check the alignment (if they are aligned to byte, word or dword boundaries (8, 16 or 32 bit). Default on a 32 bit system should be dword/32 bit (if I remember correctly). And then: > C: > RFID_API void GetErrorMessage(int nErrorCode, char* pMessage, int > nLength); VO: > _dll FUNCTION GetErrorMessage(nErrorCode as DWORD, pMessage as PSZ, > nLength AS DWORD) as VOID PASCAL:RFIDDLL.GetErrorMessage You may need to allocate first the pMessage with MemAlloc(), and free the memory afterwards. Therefore I would use ptr and not psz. Wolfgang --
[toc] | [prev] | [next] | [standalone]
| From | "Karl-Heinz" <invalid@invalid.invalid> |
|---|---|
| Date | 2016-06-01 12:37 +0200 |
| Message-ID | <dr7s82Fkp19U1@mid.individual.net> |
| In reply to | #9391 |
Hi Alex, two remarks: 1. wherever the C-Headerfile claims an INT you must use an INT and not a DWORD. e.g. GetErrorMessage() should look like: _dll FUNCTION GetErrorMessage(nErrorCode as INT, pMessage as PSZ, nLength AS INT) as VOID PASCAL:RFIDDLL.GetErrorMessage 2. When you forward the structure RFID_API to the DLL: write "AS RFID_API" instead of a simple "AS PTR" > I get back to you once I have implemented and > tested (currently waiting for the reader still) We´re waiting eagerly ;-) regards Karl-Heinz
[toc] | [prev] | [next] | [standalone]
| From | alexander.schmitt@paidosoft.de |
|---|---|
| Date | 2016-06-14 14:05 -0700 |
| Message-ID | <b21ed327-184e-482f-96ea-73b551cb6963@googlegroups.com> |
| In reply to | #9393 |
Ok, now the reader finally arrived. After issues with the driver I am now able to test :-) Basic functions like OpenReader() and GetNumberOfItems() (i.e. the RFID-tags on it) are working after I identified the correct DLL entry points using Dependency Walker. Thanks for your help! However, the application crashes when I try to read information from an RFID tag via GetItem() that uses the structure. The (shortened) declaration now is: ------ structure TRPINFO MEMBER isUserCard as logic MEMBER numberOfParts as int MEMBER uID as ptr [...further PTRs] _dll FUNCTION GetItem(nTrpNr as int, oTrpInfo as TRPINFO) as int PASCAL:RFIDDLL.?GetItem@@YAHHPAUTRPINFO@@@Z ------ From VO I call: ----- local ptrStruct is TRPINFO ptrStruct.isUserCard:=false ptrStruct.numberOfParts:=0 ptrStruct.uID:=MemAlloc(17) Qout(“before”) nRet:=GetItem(nItem, @ptrStruct) Qout(“after”) ------ The application crashes hardly when GetItem is called without the VO error handler popping up. Qout(“after”) is never reached. Log files of the supplier from within the DLL’s GetItem function indicate that this happens when the function tries to populate my string “uID”, probably due to memory issues. Some thoughts: - I am not quite clear whether to use “AS” or “IS” when defining ptrStruct. VO-help says that “IS” is taking care of memory allocation whereas “AS” doesn’t. Exchanging AS/IS doesn’t help. - Increasing the size of MemAlloc(17) to e.g. MemAlloc(500) does not help, besides “17” is the recommended value from the DLL provider. Maybe I have to add another byte for null-terminated string? - Allocating entire space for ptrStruct using ptrStruct=MemAlloc(_sizeof(ptrStruct)) does not help either. - Call-by-reference (@) seems to be required I guess. Any clue or best practice to allocate and forward structures containing strings to a DLL function? Best, Alex
[toc] | [prev] | [next] | [standalone]
| From | "Wolfgang Riedmann" <wriedmann@gmail.com> |
|---|---|
| Date | 2016-06-15 08:59 +0200 |
| Message-ID | <dscclvFk7pU1@mid.individual.net> |
| In reply to | #9429 |
Hi Alex, AFAIK structures are passed always by reference. So you don't need to use the "@" operator - otherwise you are passing the pointer to the structure allocation, and of course the program crashes badly. And personally I would use "as" for the structure declaration, and allocate the memory using MemAlloc() (and MemFree afterwards). So you make sure that the structure is not in the dynamic memory. HTH Wolfgang alexander.schmitt@paidosoft.de wrote: > Ok, now the reader finally arrived. After issues with the driver I am > now able to test :-) > > Basic functions like OpenReader() and GetNumberOfItems() (i.e. the > RFID-tags on it) are working after I identified the correct DLL entry > points using Dependency Walker. Thanks for your help! > > However, the application crashes when I try to read information from > an RFID tag via GetItem() that uses the structure. > > The (shortened) declaration now is: > ------ > structure TRPINFO > MEMBER isUserCard as logic > MEMBER numberOfParts as int > MEMBER uID as ptr > [...further PTRs] > > _dll FUNCTION GetItem(nTrpNr as int, oTrpInfo as TRPINFO) as int > PASCAL:RFIDDLL.?GetItem@@YAHHPAUTRPINFO@@@Z ------ > > From VO I call: > > ----- > local ptrStruct is TRPINFO > > ptrStruct.isUserCard:=false > ptrStruct.numberOfParts:=0 > ptrStruct.uID:=MemAlloc(17) > > > Qout(“before”) > nRet:=GetItem(nItem, @ptrStruct) > Qout(“after”) > ------ > > The application crashes hardly when GetItem is called without the VO > error handler popping up. Qout(“after”) is never reached. > > Log files of the supplier from within the DLL’s GetItem function > indicate that this happens when the function tries to populate my > string “uID”, probably due to memory issues. > > Some thoughts: > > - I am not quite clear whether to use “AS” or “IS” when > defining ptrStruct. VO-help says that “IS” is taking care of > memory allocation whereas “AS” doesn’t. Exchanging AS/IS > doesn’t help. > > - Increasing the size of MemAlloc(17) to e.g. MemAlloc(500) does not > help, besides “17” is the recommended value from the DLL > provider. Maybe I have to add another byte for null-terminated string? > > - Allocating entire space for ptrStruct using > ptrStruct=MemAlloc(_sizeof(ptrStruct)) does not help either. > > - Call-by-reference (@) seems to be required I guess. > > > Any clue or best practice to allocate and forward structures > containing strings to a DLL function? > > Best, > Alex --
[toc] | [prev] | [next] | [standalone]
| From | "Karl-Heinz" <invalid@invalid.invalid> |
|---|---|
| Date | 2016-06-15 09:40 +0200 |
| Message-ID | <dscf3pF13neU1@mid.individual.net> |
| In reply to | #9429 |
Hi Alex, >local ptrStruct is TRPINFO > >ptrStruct.isUserCard:=false >ptrStruct.numberOfParts:=0 >ptrStruct.uID:=MemAlloc(17) > > >Qout(“before”) >nRet:=GetItem(nItem, @ptrStruct) >Qout(“after”) > >The application crashes hardly when GetItem is called without > the VO error handler popping up. Qout(“after”) is never reached. First of all you should tell us exactly what GetItem() does. - which members must be filled before calling GetItem() ? - which members are filled by the C-DLL ? Guessing that the C-DLL writes at least a string to "uID" , you might try it with a modfied structure ------------------ structure TRPINFO member isUserCard as logic member numberOfParts as int Member Dim uI[17] as byte // 17 recommended buffersize ? --------------- local ptrStruct is trpinfo local nID, nRet as int // reason to setup these members? ptrStruct.isUserCard:=false ptrStruct.numberOfParts:=0 // purpose of "nID" ? nRet := GetItem ( nID , @ptrStruct ) //assuming nRet holds an errorcode if nRet == <AllesOk > ? psz2string ( @ptrStruct.uID[1] ) else ? nRet endif >Basic functions like OpenReader() and GetNumberOfItems() (i.e. the >RFID-tags on it) are working > after I identified the correct DLL entry points using Dependency Walker. Wondering, though the C-Headerfile e.g. publishes the Functionname "GetItem", you´re not able to import the function using that name ... regards Karl-Heinz
[toc] | [prev] | [next] | [standalone]
| From | "Gerhard Bunzel" <g.bunzel@domonet.de> |
|---|---|
| Date | 2016-06-15 14:34 +0200 |
| Message-ID | <njri0l$ef7$1@news.m-online.net> |
| In reply to | #9429 |
Alexander, >....besides “17” is the recommended value from the DLL provider. Then you maybe have to use 'ALIGN 1' to declare that data structure. From VO-Help: Explicit (manual ) Structure Alignment In some situations you need to match a structure declaration from a C/C++ header file that has explicit alignment. Then you need to add the ALIGN clause to your structure declaration. This forces the compiler to align the structure elements to a multiple of the specified size. An alignment of 1 tells the compiler NOT to use padding but to align all elements of a structure next to eachother. This is the most compact, but may be slower. Search for 'ALIGN' in the VO helpfile Do you have a C-Sample to use that DLL? HTH Gerhard Bunzel schrieb im Newsbeitrag news:b21ed327-184e-482f-96ea-73b551cb6963@googlegroups.com... Ok, now the reader finally arrived. After issues with the driver I am now able to test :-) Basic functions like OpenReader() and GetNumberOfItems() (i.e. the RFID-tags on it) are working after I identified the correct DLL entry points using Dependency Walker. Thanks for your help! However, the application crashes when I try to read information from an RFID tag via GetItem() that uses the structure. The (shortened) declaration now is: ------ structure TRPINFO MEMBER isUserCard as logic MEMBER numberOfParts as int MEMBER uID as ptr [...further PTRs] _dll FUNCTION GetItem(nTrpNr as int, oTrpInfo as TRPINFO) as int PASCAL:RFIDDLL.?GetItem@@YAHHPAUTRPINFO@@@Z ------ From VO I call: ----- local ptrStruct is TRPINFO ptrStruct.isUserCard:=false ptrStruct.numberOfParts:=0 ptrStruct.uID:=MemAlloc(17) Qout(“before”) nRet:=GetItem(nItem, @ptrStruct) Qout(“after”) ------ The application crashes hardly when GetItem is called without the VO error handler popping up. Qout(“after”) is never reached. Log files of the supplier from within the DLL’s GetItem function indicate that this happens when the function tries to populate my string “uID”, probably due to memory issues. Some thoughts: - I am not quite clear whether to use “AS” or “IS” when defining ptrStruct. VO-help says that “IS” is taking care of memory allocation whereas “AS” doesn’t. Exchanging AS/IS doesn’t help. - Increasing the size of MemAlloc(17) to e.g. MemAlloc(500) does not help, besides “17” is the recommended value from the DLL provider. Maybe I have to add another byte for null-terminated string? - Allocating entire space for ptrStruct using ptrStruct=MemAlloc(_sizeof(ptrStruct)) does not help either. - Call-by-reference (@) seems to be required I guess. Any clue or best practice to allocate and forward structures containing strings to a DLL function? Best, Alex
[toc] | [prev] | [next] | [standalone]
| From | alexander.schmitt@paidosoft.de |
|---|---|
| Date | 2016-06-15 14:06 -0700 |
| Message-ID | <ca6db81c-f61c-4d71-9aac-8ebe6b9be7aa@googlegroups.com> |
| In reply to | #9432 |
Hi Wolfang, Karl-Heinz, Gerhard,
great support, thanks!
@Wolfgang:
"@" seems required for "IS" to indicate the call-by-reference, for "AS" no "@" is required or possible. Reference seems implicit.
BTW: Exchanging AS (+allocating) / IS (no allocating) does not help.
@Karl-Heinz:
> First of all you should tell us exactly what GetItem() does.
> - which members must be filled before calling GetItem() ?
> - which members are filled by the C-DLL ?
GetItem(nItem, ptrStruc) actually fetches all information written on the RFID tag identified by a number "nItem" and writes it into the structure "ptrStruc" that is called by reference from VO. E.g. ID-Number of the tag, author, ISBN number, etc. If there is e.g. only one tag on the reader, then the item can be addressed with nItem=0 (meaning actually the first and only one).
There is no need to initialize anything, i.e. everything is filled by the C-DLL. However, I also tried if initializing would help, but it ain't.
> Guessing that the C-DLL writes at least a string to "uID" , you might try it
with a modfied structure
I did try your version, but same issue. :-(
> Wondering, though the C-Headerfile e.g. publishes the Functionname "GetItem",
> you´re not able to import the function using that name ...
I was wondering too, actually. But I received "procedure entry point missing" errors without.
@Gerhard:
> Then you maybe have to use 'ALIGN 1' to declare that data structure.
I tried different alignments, but same issue. But thanks for pointing out.
> Do you have a C-Sample to use that DLL?
Only a code snippet from the API doc:
TRPINFO myInfo;
memset(&myInfo, 0, sizeof(TRPINFO));
int result = GetItem (0, &myInfo);
if (result < 0)
{
// Fehler;
…
return;
}
cout << myInfo.itemId << endl;
Pretty similar to my implementation.
I guess I have to practice with other DLLs e.g. libzip to see if I am basically able to populate structures without generating crashes ;-) and then have another iteration with the provider guys.
I'll keep you posted. May take a while...
Best,
Alex
[toc] | [prev] | [next] | [standalone]
| From | "Wolfgang Riedmann" <wriedmann@gmail.com> |
|---|---|
| Date | 2016-06-16 05:56 +0200 |
| Message-ID | <dsemc4FetruU1@mid.individual.net> |
| In reply to | #9433 |
Hi Alex,
can you send me the C header file with the structures and the function
declaration at wriedmann at gmail dot com?
Then I can try to build a rudimentary interface for you (I have
integrated several C DLLs in VO, it was my preferred integration of 3rd
party DLLs).
Wolfgang
alexander.schmitt@paidosoft.de wrote:
> Hi Wolfang, Karl-Heinz, Gerhard,
>
> great support, thanks!
>
> @Wolfgang:
>
> "@" seems required for "IS" to indicate the call-by-reference, for
> "AS" no "@" is required or possible. Reference seems implicit.
>
> BTW: Exchanging AS (+allocating) / IS (no allocating) does not help.
>
> @Karl-Heinz:
>
> > First of all you should tell us exactly what GetItem() does.
>
> > - which members must be filled before calling GetItem() ?
> > - which members are filled by the C-DLL ?
>
> GetItem(nItem, ptrStruc) actually fetches all information written on
> the RFID tag identified by a number "nItem" and writes it into the
> structure "ptrStruc" that is called by reference from VO. E.g.
> ID-Number of the tag, author, ISBN number, etc. If there is e.g. only
> one tag on the reader, then the item can be addressed with nItem=0
> (meaning actually the first and only one).
>
> There is no need to initialize anything, i.e. everything is filled by
> the C-DLL. However, I also tried if initializing would help, but it
> ain't.
>
> > Guessing that the C-DLL writes at least a string to "uID" , you
> > might try it
> with a modfied structure
>
> I did try your version, but same issue. :-(
>
> > Wondering, though the C-Headerfile e.g. publishes the Functionname
> > "GetItem", you´re not able to import the function using that name
> > ...
>
> I was wondering too, actually. But I received "procedure entry point
> missing" errors without.
>
> @Gerhard:
>
>
> > Then you maybe have to use 'ALIGN 1' to declare that data structure.
>
> I tried different alignments, but same issue. But thanks for pointing
> out.
>
> > Do you have a C-Sample to use that DLL?
>
> Only a code snippet from the API doc:
>
> TRPINFO myInfo;
> memset(&myInfo, 0, sizeof(TRPINFO));
> int result = GetItem (0, &myInfo);
> if (result < 0)
> {
> // Fehler;
> …
> return;
> }
> cout << myInfo.itemId << endl;
>
> Pretty similar to my implementation.
>
> I guess I have to practice with other DLLs e.g. libzip to see if I am
> basically able to populate structures without generating crashes ;-)
> and then have another iteration with the provider guys.
>
> I'll keep you posted. May take a while...
>
> Best,
> Alex
--
[toc] | [prev] | [next] | [standalone]
| From | "Wolfgang Riedmann" <wriedmann@gmail.com> |
|---|---|
| Date | 2016-06-16 06:03 +0200 |
| Message-ID | <dsemofFevspU1@mid.individual.net> |
| In reply to | #9433 |
Hi Alex,
> "@" seems required for "IS" to indicate the call-by-reference, for
> "AS" no "@" is required or possible. Reference seems implicit.
yes, you are right.
Please see this working code from Fab Paintlib:
LOCAL pRect IS _winRECT
LOCAL Width, Height AS LONG
//
GetClientRect( hWnd, @pRect )
Width := pRect.Right - pRect.Left + 1
Height := pRect.Bottom - pRect.Top + 1
> BTW: Exchanging AS (+allocating) / IS (no allocating) does not help.
this is very strange. Do you have any piece of documentation? Some
could it be that the C DLL allocates the memory for the structure and
needs to free it afterwards? Do that you need to pass in a pointer to
the structure?
Wolfgang
>
> @Karl-Heinz:
>
> > First of all you should tell us exactly what GetItem() does.
>
> > - which members must be filled before calling GetItem() ?
> > - which members are filled by the C-DLL ?
>
> GetItem(nItem, ptrStruc) actually fetches all information written on
> the RFID tag identified by a number "nItem" and writes it into the
> structure "ptrStruc" that is called by reference from VO. E.g.
> ID-Number of the tag, author, ISBN number, etc. If there is e.g. only
> one tag on the reader, then the item can be addressed with nItem=0
> (meaning actually the first and only one).
>
> There is no need to initialize anything, i.e. everything is filled by
> the C-DLL. However, I also tried if initializing would help, but it
> ain't.
>
> > Guessing that the C-DLL writes at least a string to "uID" , you
> > might try it
> with a modfied structure
>
> I did try your version, but same issue. :-(
>
> > Wondering, though the C-Headerfile e.g. publishes the Functionname
> > "GetItem", you´re not able to import the function using that name
> > ...
>
> I was wondering too, actually. But I received "procedure entry point
> missing" errors without.
>
> @Gerhard:
>
>
> > Then you maybe have to use 'ALIGN 1' to declare that data structure.
>
> I tried different alignments, but same issue. But thanks for pointing
> out.
>
> > Do you have a C-Sample to use that DLL?
>
> Only a code snippet from the API doc:
>
> TRPINFO myInfo;
> memset(&myInfo, 0, sizeof(TRPINFO));
> int result = GetItem (0, &myInfo);
> if (result < 0)
> {
> // Fehler;
> …
> return;
> }
> cout << myInfo.itemId << endl;
>
> Pretty similar to my implementation.
>
> I guess I have to practice with other DLLs e.g. libzip to see if I am
> basically able to populate structures without generating crashes ;-)
> and then have another iteration with the provider guys.
>
> I'll keep you posted. May take a while...
>
> Best,
> Alex
--
[toc] | [prev] | [next] | [standalone]
| From | alexander.schmitt@paidosoft.de |
|---|---|
| Date | 2016-06-16 14:28 -0700 |
| Message-ID | <08f63bfb-0b7d-4229-b5b8-e372fd444c7a@googlegroups.com> |
| In reply to | #9435 |
Thanks for your kind offer, Wolfgang. I will gather some code over the weekend and send it to you. Curious if I am overseeing something heavily. Best, Alex
[toc] | [prev] | [next] | [standalone]
| From | alexander.schmitt@paidosoft.de |
|---|---|
| Date | 2016-06-19 13:23 -0700 |
| Message-ID | <59a99e28-9599-4ed1-938d-ba59a7bfc554@googlegroups.com> |
| In reply to | #9440 |
@Wolfgang: Mail is sent. PDF-documentation of the API is attached.
[toc] | [prev] | [next] | [standalone]
| From | "Wolfgang Riedmann" <wriedmann@gmail.com> |
|---|---|
| Date | 2016-06-20 07:29 +0200 |
| Message-ID | <dspd9mFiv2oU1@mid.individual.net> |
| In reply to | #9452 |
Hi Alex, > @Wolfgang: Mail is sent. PDF-documentation of the API is attached. yes, I have received it and will look into it later this week. At the first look the interface looks very simple and easy to implement. Wolfgang --
[toc] | [prev] | [next] | [standalone]
| From | "Wolfgang Riedmann" <wriedmann@gmail.com> |
|---|---|
| Date | 2016-06-21 06:21 +0200 |
| Message-ID | <dsrtlvF3t6rU1@mid.individual.net> |
| In reply to | #9433 |
Hi Alex,
I have no reader, but I think I have been able to understand what's
going on.
The C header file defines things like this:
EASYCHECK_API int OpenReader();
EASYCHECK_API int OpenReader(char* readerport);
EASYCHECK_API int CloseReader();
EASYCHECK_API int CloseReader(char* readerport);
the same function name with different parameters. VO cannot deal with
this.
So I think this is a C++ DLL, and using depends.exe I have found
different exported functions that seem to work - they are prefixed with
Bib, using for example
_dll function BibOpenReader() as int pascal:EasyCheck.BibOpenReader
Try to ask the producer of the DLL of this is the correct C interface -
not C++!
In the VO help there is a section about integrating also C++ dlls, but
I have no experience with it.
Wolfgang
alexander.schmitt@paidosoft.de wrote:
> Hi Wolfang, Karl-Heinz, Gerhard,
>
> great support, thanks!
>
> @Wolfgang:
>
> "@" seems required for "IS" to indicate the call-by-reference, for
> "AS" no "@" is required or possible. Reference seems implicit.
>
> BTW: Exchanging AS (+allocating) / IS (no allocating) does not help.
>
> @Karl-Heinz:
>
> > First of all you should tell us exactly what GetItem() does.
>
> > - which members must be filled before calling GetItem() ?
> > - which members are filled by the C-DLL ?
>
> GetItem(nItem, ptrStruc) actually fetches all information written on
> the RFID tag identified by a number "nItem" and writes it into the
> structure "ptrStruc" that is called by reference from VO. E.g.
> ID-Number of the tag, author, ISBN number, etc. If there is e.g. only
> one tag on the reader, then the item can be addressed with nItem=0
> (meaning actually the first and only one).
>
> There is no need to initialize anything, i.e. everything is filled by
> the C-DLL. However, I also tried if initializing would help, but it
> ain't.
>
> > Guessing that the C-DLL writes at least a string to "uID" , you
> > might try it
> with a modfied structure
>
> I did try your version, but same issue. :-(
>
> > Wondering, though the C-Headerfile e.g. publishes the Functionname
> > "GetItem", you´re not able to import the function using that name
> > ...
>
> I was wondering too, actually. But I received "procedure entry point
> missing" errors without.
>
> @Gerhard:
>
>
> > Then you maybe have to use 'ALIGN 1' to declare that data structure.
>
> I tried different alignments, but same issue. But thanks for pointing
> out.
>
> > Do you have a C-Sample to use that DLL?
>
> Only a code snippet from the API doc:
>
> TRPINFO myInfo;
> memset(&myInfo, 0, sizeof(TRPINFO));
> int result = GetItem (0, &myInfo);
> if (result < 0)
> {
> // Fehler;
> …
> return;
> }
> cout << myInfo.itemId << endl;
>
> Pretty similar to my implementation.
>
> I guess I have to practice with other DLLs e.g. libzip to see if I am
> basically able to populate structures without generating crashes ;-)
> and then have another iteration with the provider guys.
>
> I'll keep you posted. May take a while...
>
> Best,
> Alex
--
[toc] | [prev] | [next] | [standalone]
| From | alexander.schmitt@paidosoft.de |
|---|---|
| Date | 2016-06-22 12:37 -0700 |
| Message-ID | <eb58b76f-88bc-4e24-a2bd-19b6122f82d8@googlegroups.com> |
| In reply to | #9460 |
Hi Wolfgang, Thanks for your analysis! Interestingly enough, I have been able to successfully call the C++-DLLs although they overload each other. Using the @-convention, I can particularly address the correct DLL-function: _dll FUNCTION rfidOpenReaderWithPort(ptrReaderport as ptr) as int PASCAL:EASYCHECK.?OpenReader@@YAHPAD@Z _dll FUNCTION rfidOpenReader() as int PASCAL:EASYCHECK.?OpenReader@@YAHXZ rfidOpenReader() does return a correct value; also retrieving the number of RFID tags placed on the reader can be identified: _dll FUNCTION rfidGetNumberOfItems() as int PASCAL:EASYCHECK.?GetNumberOfItems@@YAHXZ The only issue is that the function _dll FUNCTION rfidGetItem(nTrpNr as int, oTrpInfo as TRPINFO) as int PASCAL:EASYCHECK.?GetItem@@YAHHPAUTRPINFO@@@Z crashes when it tries to write the first PSZ within the oTrpInfo struc (according to the provider's log file). Although the provider has exposed C++ functions, they still are not object oriented. I.e. writing wrappers for classes is not required. I have found the C++-DLL tutorial on the help. Thanks for giving me the hint. Looks rather complex though. Before diving into that, I will follow your good suggestion to ask the provider for exposing the (already existing) C functions, that are also present in the DLL. Keep you posted. Best, Alex
[toc] | [prev] | [next] | [standalone]
| From | "Wolfgang Riedmann" <wriedmann@gmail.com> |
|---|---|
| Date | 2016-06-23 04:05 +0200 |
| Message-ID | <dt0ug2F4fhmU1@mid.individual.net> |
| In reply to | #9479 |
Hi Alex, > _dll FUNCTION rfidGetItem(nTrpNr as int, oTrpInfo as TRPINFO) as int > PASCAL:EASYCHECK.?GetItem@@YAHHPAUTRPINFO@@@Z > > crashes when it tries to write the first PSZ within the oTrpInfo > struc (according to the provider's log file). IMHO the C++ calling convention does something different that makes your application crash (I can be wrong, though) > > Although the provider has exposed C++ functions, they still are not > object oriented. I.e. writing wrappers for classes is not required. > > Before diving into that, I will follow your good suggestion to ask > the provider for exposing the (already existing) C functions, that > are also present in the DLL. personally I think they have exposed them already with the Bib... prefix I would try this set of functions..... Wolfgang --
[toc] | [prev] | [next] | [standalone]
| From | alexander.schmitt@paidosoft.de |
|---|---|
| Date | 2016-07-03 13:53 -0700 |
| Message-ID | <d7c1a3f6-5324-40b4-8496-2a3346bdcd9b@googlegroups.com> |
| In reply to | #9481 |
Hi Wolfgang, Karl-Heinz,
after installing Visual Studio 2015 and creating my own DLL in C++, I could finally track down the issue.
Root cause was a concatenation of errors:
The structure was
struct RFID_API TRPINFO
{
bool isUserCard;
...
int numberOfParts;
...
char *uID;
...
}
Here my lessons-learned:
- I translated "bool" in most of my attempts with VO-type "logic"
- Correct would have been "byte".
- I guess that "logic" is > 1 Byte and "byte"=1 byte. Thereby the structure must have been shifted. Although I've also tried with byte, there was a second mistake I did: calling the C++ function explicitely by reference: function(@struct) instead of function(struct). That also caused aborts.
Thanks for your support! I am now able to read my RFID tags.
Best,
Alex
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.clipper.visual-objects
csiph-web