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

callback functions in unmanaged code(urgent)

I've to invoke a unmanaged dll fucntion in C# which uses
a callback fucntion.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
PBORCA_MAXCOMMENT=255
***************************************
End of the dll fucntion
***************************************

_________________________________________
C# code which I've written
_________________________________________

[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;
[MarshalAsUnmanagedType.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")]
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);
char[] st = new char[10000];
GC.KeepAlive(code=class3.LibraryEntry
(hnd,"d:\\projects\\current\\tgt3.pbl",st,10000,c, usr));

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

}

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 structure and
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

Thanks in advance,
Vijaya
..
Jul 21 '05 #1
0 1711

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

Similar topics

1
by: Rob | last post by:
Hi everyone, I'm having some big JS problems - my function is making my html code vanish, and I need help! Here's the code, try it for yourself. You'll notice that when you click either links...
8
by: gremlinbass | last post by:
I was wondering if I can check to see if a file is open? Specifically, is there any way I can code Access to check to see if a text file (datasource.txt to be specific) is open, returning a true...
1
by: R-D-C | last post by:
Hi, I have a client who uses a web service containing about 100 functions. I made a couple of changes to four functions, tested it (fine), deployed to VMWare virtual machine (still working...
0
by: vijaya | last post by:
I've to invoke a unmanaged dll fucntion in C# which uses a callback fucntion.The unmanaged dll fucntion is as follows **************************************** The Original Fucntion in the dll...
0
by: tanmay7551 | last post by:
2)The developer of Accutech Technology is writing a code in VB.NET. He wants that when he clicks on Button1, the Button1 should display the "SCORMCourseItemMaster" crystal report. In addition, he...
7
by: Hemant Pathak | last post by:
Hi programmers............................... i want to sending fax through vb code it is my client requrement is it possible or not if possible then how can i do? Please tell me it is...
3
by: pradeepm | last post by:
Hii Anybody have source code for JAVA B+ trees.Pls send me.Very urgent.Thanks in advance.
1
by: gregalliance | last post by:
m retriving a variable's value which is in javascript into an function in asp,but asp is not able to read dat variable's value,plz direct me for it,its urgent for ma project work.
5
by: gopim | last post by:
strSql = "SELECT ISNULL(max(substring(User_ID,2,len(User_ID))) + 1,'100') FROM Users"; sqlCmd.CommandText = strSql; sqlDr = sqlCmd.ExecuteReader(); ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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...

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.