473,586 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_LibraryD irectory ( 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_LibraryD irectory callback
function.

pUserData -Pointer to user data to be passed to the
PBORCA_LibraryD irectory callback function

Given below function is the callback function declaration
in C.

typedef void (FAR PASCAL *PBORCA_LISTPRO C) (
PPBORCA_DIRENTR Y, LPVOID );

PPBORCA_DIRENTR Y -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_UserDataIn fo
{
LPSTR lpszBuffer; // Buffer for entry info
DWORD dwCallCount; // # of entries in lib
DWORD dwBufferSize; // size of buffer
DWORD dwBufferOffset; // current offset in buffer
} ORCA_USERDATAIN FO, FAR *PORCA_USERDATA INFO;

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

typedef struct pborca_direntry { CHAR szComments
[PBORCA_MAXCOMME NT + 1];
LONG lCreateTime;
LONG lEntrySize;
LPSTR lpszEntryName;
PBORCA_TYPE otEntryType;} PBORCA_DIRENTRY , FAR
*PPBORCA_DIRENT RY;

Note:PBORCA_TYP E is an enum
PBORCA_MAXCOMME NT=255
*************** *************** *********
End of the dll fucntion
*************** *************** *********

_______________ _______________ ___________
C# code which I've written
_______________ _______________ ___________

[StructLayout(La youtKind.Sequen tial,CharSet=Ch arSet.Auto)]
public class UserData
{
public string s;
public uint callcount;
public uint bufsize;
public uint offset;
}
[StructLayout(La youtKind.Sequen tial,CharSet=Ch arSet.Auto)]
public struct pborca_direntry
{
public const int i=255;
[MarshalAsUnmana gedType.ByValTS tr,SizeConst=i+ 1)]
public string s;
public System.Int32 time;
public System.Int32 size;
[MarshalAs(Unman agedType.LPStr)]
public string name;
public int type;
}
public unsafe delegate void Callback(ref pborca_direntry
p,UserData usr);

[DllImport
("pborc80.dll", CharSet=CharSet .Auto,EntryPoin t="PBORCA_Lib r
aryDirectory")]
public static extern int LibraryEntry(in t hnd,[MarshalAs
(UnmanagedType. LPStr)]System.String s,[Out]char[] buff,int
se,[MarshalAs(Unman agedType.Functi onPtr)]Callback
hr,UserData usr);


public class1
{
Callback c = new Callback(Class1 .libdircallback );
char[] st = new char[10000];
GC.KeepAlive(co de=class3.Libra ryEntry
(hnd,"d:\\proje cts\\current\\t gt3.pbl",st,100 00,c,usr));

public static void libdircallback( ref pborca_direntry
s,UserData usr)
{
Console.WriteLi ne("hai,I'm in callback");
Console.WriteLi ne(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 1743

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

Similar topics

1
1218
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 and then look at the source code, it's all gone, apart from what the function is writing. How can I make the code just append the result under the...
8
1412
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 value and creating a loop? Then, once the file closes, return a false value and closing the loop? I need to run a batch file using Shell() and...
1
1264
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 great) and then to their live system. On the live system the four functions no longer work. When testing using Internet Explorer browsing to the...
0
235
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 **************************************** int PBORCA_LibraryDirectory ( HPBORCA hORCASession, LPSTR lpszLibName, LPSTR lpszLibComments, int...
0
1041
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 wants to display predefined string and day of the week in that crystal report. He is specifying the following code on the click of the Button1: ...
7
8437
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 urgent........
3
4500
by: pradeepm | last post by:
Hii Anybody have source code for JAVA B+ trees.Pls send me.Very urgent.Thanks in advance.
1
1635
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
1686
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(); sqlDr.Read(); UserID = "U" + sqlDr.GetValue(0); after this i write insert query. in that insert query my user_Id value will be like...
0
7908
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7836
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8199
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8212
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5389
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2343
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1447
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.