from c native w32 dll char * and working VB 6 code to a C# DLLImport

C

caviar

Hi,

i'm having a problem with a native w32 dll. Everything is working fine
except for one parameter which is defined as:
--------------------------------------header file---
// short PASFIX PAF_GetRecord(short listndx, long recno,char *pafrec, short
pafreclen );

I'm having problems with the char *pafrec param, i translated (after
many/many/many) into this below, after trying several other usenet posting
suggesting stringbuilder, String etc.
-------------------------------------dllimport---------------------------
[DllImport("pafutw32.dll", CharSet = CharSet.Ansi, BestFitMapping= false,
ThrowOnUnmappableChar = true )]
unsafe public static extern short PAF_GetRecord(short listndx, short
recno, out string pafrec, ref short pafreclen );
----------
I get a Null value from this pafrec string, if i do a ref, it will be the
same value as i used there.

The working VB code is shown below, i'm not sure what this Dim . as string*
10000 is doing, i believe that would be the hint to get a DLLImport
declaration working.. But i for a starter do not know what *1000 is doing
there...

_Anyone knows what that line is supposed to do?_
_And, how can i pass that third parameter in there so i get a filled string
object back?_

TIA,
regards
Henk j M

------------------------------ vb code

Declare Function PAF_GetRecord Lib "pafutw32.dll" (ByVal lstndx As Integer,
ByVal recno As Long, ByVal rec As String, ByVal reclen As Integer) As
Integer

Dim rec As String * 10000
rec = ""
pafretc = PAF_GetRecordSize(lstndx, CInt(Text1.Text), recsize)
pafretc = PAF_GetRecord(lstndx, CInt(Text1.Text), rec, recsize)

----------------------PAF_GetRecordSize() --------from the manual
Function: PAF_GetRecordSize()



Syntax: short PAF_GetRecordSize(short listndx,long recno,

short *pafrecsizeptr);



Parameters: listndx is the internal reference to a hit list, obtained from
a call to PAF_SeekTerm() or PAF_CombineLists() or PAF_CombineAll().

recno is the record number within the list
(zero-origin)

pafrecsizeptr points to a short integer at which the length of the processed
Postcode record (including trailing null) will be placed



Returns: Zero if successful, see section 6 for other values



Description: Obtains the full length of the processed Postcode record with
relative record number recno in hit list listndx



Example:



Notes: The processed record is translated from the raw Postcode
record in internal storage. It is larger because all the 1-character data
item tags are expanded to 4 characters, and the 1-character data item
terminators become 2 characters.



See also: PAF_GetRawRecord(),PAF_GetRecord()
 
K

Kuba Florczyk

Hi,
i'm having a problem with a native w32 dll. Everything is working fine
except for one parameter which is defined as:
--------------------------------------header file---
// short PASFIX PAF_GetRecord(short listndx, long recno,char *pafrec, short
pafreclen );

I'm having problems with the char *pafrec param, i translated (after
many/many/many) into this below, after trying several other usenet posting
suggesting stringbuilder, String etc.
-------------------------------------dllimport---------------------------
[DllImport("pafutw32.dll", CharSet = CharSet.Ansi, BestFitMapping= false,
ThrowOnUnmappableChar = true )]
unsafe public static extern short PAF_GetRecord(short listndx, short
recno, out string pafrec, ref short pafreclen );
----------
I get a Null value from this pafrec string, if i do a ref, it will be the
same value as i used there.

The working VB code is shown below, i'm not sure what this Dim . as string*
10000 is doing, i believe that would be the hint to get a DLLImport
declaration working.. But i for a starter do not know what *1000 is doing
there...

_Anyone knows what that line is supposed to do?_
_And, how can i pass that third parameter in there so i get a filled string
object back?_

Try

CharSet = CharSet.Auto
or without set a CharSet

I've got the same problem today. In my function work without setting CharSet
and I don't know why :)

kuba f.
 
C

caviar

Kuba Florczyk said:
CharSet = CharSet.Auto
or without set a CharSet

I've got the same problem today. In my function work without setting CharSet
and I don't know why :)

kuba f.

thnx, for the reply, This didnt work either.. So back to (visual) basic..
 
M

Mattias Sjögren

I'm having problems with the char *pafrec param, i translated (after
many/many/many) into this below, after trying several other usenet posting
suggesting stringbuilder, String etc.
-------------------------------------dllimport---------------------------
[DllImport("pafutw32.dll", CharSet = CharSet.Ansi, BestFitMapping= false,
ThrowOnUnmappableChar = true )]
unsafe public static extern short PAF_GetRecord(short listndx, short
recno, out string pafrec, ref short pafreclen );

Try it like this instead

[DllImport("pafutw32.dll", CharSet = CharSet.Ansi, BestFitMapping =
false, ThrowOnUnmappableChar = true )]
public static extern short PAF_GetRecord(short listndx, int recno,
StringBuilder pafrec, short pafreclen );




Mattias
 
C

caviar

Mattias Sjögren said:
I'm having problems with the char *pafrec param, i translated (after
many/many/many) into this below, after trying several other usenet posting
suggesting stringbuilder, String etc.
-------------------------------------dllimport---------------------------
[DllImport("pafutw32.dll", CharSet = CharSet.Ansi, BestFitMapping= false,
ThrowOnUnmappableChar = true )]
unsafe public static extern short PAF_GetRecord(short listndx, short
recno, out string pafrec, ref short pafreclen );

Try it like this instead

[DllImport("pafutw32.dll", CharSet = CharSet.Ansi, BestFitMapping =
false, ThrowOnUnmappableChar = true )]
public static extern short PAF_GetRecord(short listndx, int recno,
StringBuilder pafrec, short pafreclen );

Thanx, but tried this one also.. its also often suggested in the
Newsgroups.. But doesnt work for me

It seems to be a MultiByte Char.. I dont no how i can read that back in to a
unicode string.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top