473,396 Members | 1,810 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,396 software developers and data experts.

PInvoke query

I've a problem with PInvoke.I've to invoke a unmanaged dll
fucntion in C# which uses a callback fucntion.Please
apologise for this lenghty message and render ur kind help.
The original dll function and my C# code has been given
below along with the error message.

Error: The return code is 0 which means the fucntion has
executed successfully. But I'm not getting the correct
values in the structure pborcadirentry.
Note: I've tried GC method. But I'm not sure whether I've
applied it appropriately.I've also tried [MarshalAs
(UnmanagedType.Struct)] and [MarshalAs
(UnmanagedType.LPStruct)] for marshaling strcuture ans
class.
But there was no change in the o/p. I feel that there is
some problem with the memory. But I'm unable to detect it.
Please help me


The unmanaged dll fucntion is as follows

****************************************
The Original Fucntion in the dll
****************************************
int PBORCA_LibraryDirectory ( HPBORCA hORCASession, LPSTR
lpszLibName, LPSTR lpszLibComments, int iCmntsBuffSize,
PBORCA_LISTPROC pListProc, LPVOID pUserData );

hORCASession-Handle to previously established ORCA session

pListProc- Pointer to the PBORCA_LibraryDirectory callback
function.

pUserData -Pointer to user data to be passed to the
PBORCA_LibraryDirectory callback function

Given below function is the callback function declaration
in C.

typedef void (FAR PASCAL *PBORCA_LISTPROC) (
PPBORCA_DIRENTRY, LPVOID );

PPBORCA_DIRENTRY -Pointer to the structure
PBORCA_DIRENTRY, described next
LPVOID -Long pointer to user data

The user data strcuture to the callback fucntion is as
follows:

typedef struct ORCA_UserDataInfo
{
LPSTR lpszBuffer; // Buffer for entry info
DWORD dwCallCount; // # of entries in lib
DWORD dwBufferSize; // size of buffer
DWORD dwBufferOffset; // current offset in buffer
} ORCA_USERDATAINFO, FAR *PORCA_USERDATAINFO;

The structure passed to the callback fucntion by the
LibraryDirectory fucntion is as follows:

typedef struct pborca_direntry { CHAR szComments
[PBORCA_MAXCOMMENT + 1];
LONG lCreateTime;
LONG lEntrySize;
LPSTR lpszEntryName;
PBORCA_TYPE otEntryType;} PBORCA_DIRENTRY, FAR
*PPBORCA_DIRENTRY;

Note:PBORCA_TYPE is an enum

***************************************
End of the dll fucntion
***************************************

_________________________________________
C# code
_________________________________________

[StructLayout(LayoutKind.Sequential,CharSet=CharSet .Auto)]
public class UserData
{
public string s;
public uint callcount;
public uint bufsize;
public uint offset;
}
[StructLayout(LayoutKind.Sequential,CharSet=CharSet .Auto)]
public struct pborca_direntry
{
public const int i=255;
[MarshalAs
(UnmanagedType.ByValTStr,SizeConst=i+1)]
public string s;
public System.Int32 time;
public System.Int32 size;
[MarshalAs(UnmanagedType.LPStr)]
public string name;
public int type;
}
public unsafe delegate void Callback(ref pborca_direntry
p,UserData usr);

[DllImport
("pborc80.dll",CharSet=CharSet.Auto,EntryPoint="PB ORCA_Libr
aryDirectory",CallingConvention=CallingConvention. StdCall)]
//...Ansi)]
public static extern int LibraryEntry(int hnd,[MarshalAs
(UnmanagedType.LPStr)]System.String s,[Out]char[] buff,int
se,[MarshalAs(UnmanagedType.FunctionPtr)]Callback
hr,UserData usr);


public class1
{
Callback c = new Callback(Class1.libdircallback);

GC.KeepAlive(code=class3.LibraryEntry
(hnd,"d:\\projects\\current\\tgt3.pbl",st,10000,c, usr));

public unsafe static void libdircallback(ref
pborca_direntry s,UserData usr) {
{
Console.WriteLine("hai,I'm in
callback");
Console.WriteLine
(s.type);
}

}
Thanks in advance,
Vijaya
Nov 22 '05 #1
0 1278

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

Similar topics

4
by: Ted | last post by:
Is it possible to use mailslots in .NET using PInvoke? I have a VC++ 6.0 based app that creates and listens to a mailslot. I have a second VC++ 6.0 based app that opens the mailslot and writes...
0
by: vijaya | last post by:
I've a problem with PInvoke.I've to invoke a unmanaged dll fucntion in C# which uses a callback fucntion.Please apologise for this lenghty message and render ur kind help. The original dll...
5
by: Carlos Guzmán Álvarez | last post by:
Hello: I'm trying to execute a function of a unmanaged dll using PInvoke, i have definied the function as: public static extern int isc_dsql_prepare( int status_vector, ref int...
2
by: Jeff Lederer | last post by:
I have created a simple test C# console program that calls an unmanaged C subroutine in a DLL where one of the arguments is a callback to the C# code. I noticed that when the callback has no...
3
by: Brett Robichaud | last post by:
I have created a simple background thread to make one pinvoke call into a DLL I've created. My Winforms app spawns the thread in the form load event then go about it's business. The problem is...
5
by: vertigo | last post by:
Hello I use some win 32 API function for example: HANDLE CreateFile( LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD...
5
by: _iycrd | last post by:
After numerous problems, I'm having second thoughts about using C++/CLI to wrap a native DLL. On the other hand, PInvoke seems like it will take a huge amount of work, if it will work at all. ...
8
by: Rajesh Soni | last post by:
Hi! I'm getting a PInvoke error while trying to execute the following code... declaration: Structure POINTAPI Dim x As IntPtr
0
by: Benosham | last post by:
I have been playing around with trying to PInvoke GDI+ from C#, I made recently made the transition from C/C++ to C# and I really like the language, however being the old fashioned programmer I am I...
14
by: Mohamed Mansour | last post by:
Hey there, this will be somewhat a long post, but any response is appreciated! I have done many PInvoke in the past from C++ to C#, but I did PInvoke within C# not C++/CLI. Can someone explain...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.