Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Wolfgang Riedmann" Newsgroups: comp.lang.clipper.visual-objects Subject: Re: How to integrate C DLL into VO and generate interface code Date: Wed, 15 Jun 2016 08:59:08 +0200 Lines: 88 Message-ID: References: <66abaae4-be73-486e-a8d8-b44d0592b744@googlegroups.com> <7de24866-5bfe-439f-befb-099a84afe0d0@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: individual.net 2E6CoKl/vFqV0P+/xBuuswxOmE516Zhvj/drnuzbCvpAZIifE= Cancel-Lock: sha1:lf6jFuK4Eqz+xko0+2MZFCS4HsE= User-Agent: XanaNews/1.18.1.6 Xref: csiph.com comp.lang.clipper.visual-objects:9430 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 --