473,412 Members | 5,361 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

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

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()
Nov 15 '05 #1
5 2373
> 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.
Nov 15 '05 #2
Btw: Try ref in function :)

kuba f.
Nov 15 '05 #3

"Kuba Florczyk" <ch******@poczta.onet.pl> wrote in message
news:O8**************@TK2MSFTNGP11.phx.gbl...
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..
Nov 15 '05 #4
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 15 '05 #5

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I'm having problems with the char *pafrec param, i translated (after
many/many/many) into this below, after trying several other usenet postingsuggesting 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.
Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: JRB | last post by:
I need to read from and write to USB and RS-232 ports in a new project I'm working on. I was thinking about using C#, but I'm not sure if there's a way to do this in that language. If not, any...
4
by: Tim Menninger | last post by:
Just started working on this and have not found any real good resources out there. We have a lot of native C++ Dll code that we use for our app. We want to share the code so that C# ASP.net code...
2
by: Adam Hartshorne | last post by:
I have just upgraded to Visual Studio 2005 and have loaded in a project i have been working on, and the code compiles ok but fails to link correctly, as shown below. Any suggestions about what is...
5
by: Stephen Cawood | last post by:
I'm trying to use a C++ .lib from C# (I tried the Interop group will no results). I have a working wrapper DLL (I can get back simple things like int), but I'm having issues dealing with an array...
5
by: Ole | last post by:
Hi, I have a native dll that has a byte array to which I want a pointer to in my C# application but I will need some help to do that. the dll exports this function: void DllFunction (PBYTE...
6
by: Aston Martin | last post by:
Hi All, ********************** My Situation ********************** I am working on project that involves passing a structure to unmanaged code from .Net world (well using C#). Perhaps an example...
10
by: safaci2000 | last post by:
Hi all, I have a DLL that I need to access. I've managed to load it and unload it successfully. The compiler is happy no complaints or warning. I need to refer to a class object that was...
4
by: MichK | last post by:
Hello all, I'm having some problems passing strings to a native (unmanaged) c++ dll I've written. There are lots of examples I can find on the internet considering passing strings to char*, yet I...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.