473,398 Members | 2,404 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,398 software developers and data experts.

C DLL Callback to VB.NET 2005

I am calling an c dll function which has a callback. The callback gets
called once and my grid gets populated. The grid should have 4 rows, but as
soon as the first row gets populated the programs halts with an error:
Attempted to read or write protected memory. This is often an indication
that other memory is corrupt. Calling the function from Delphi works great
and returns 4 rows. It uses cdelc for calling convention, I tried using the
line below:

<DllImport("remotapi.dll", CallingConvention:=CallingConvention.Cdecl)> _
Sub rlist(ByRef INRLIST_PARMS As TRLIST_PARMS, ByRef INRLIST_RESP As
TRLIST_RESP, ByVal incb As ListDelegate)
End Sub

I end up with the same error. Any ideas would be appreciated. Thanks
Form1

Private Sub RLIST_POPULATE(ByRef RLIST_DETAIL As TRLIST_DETAIL)
Try
Dim source As String = StripNull(RLIST_DETAIL.source_name)
Dim RegNum As String = StripNull(RLIST_DETAIL.request_nbr)
Dim Target As String = StripNull(RLIST_DETAIL.target_name)
Dim ref_id_1 As String = StripNull(RLIST_DETAIL.ref_id_1)
Dim ref_id_2 As String = StripNull(RLIST_DETAIL.ref_id_2) & " "
Dim lvDate As String = StripNull(RLIST_DETAIL.creation_date)
Dim lvTime As String = StripNull(RLIST_DETAIL.creation_time)
Dim row1 As String() = {source, RegNum, Target, ref_id_1,
ref_id_2, lvDate, lvTime}
grd.Rows.Add(row1)
grd.Refresh()
Catch
MessageBox.Show("Error in Populate")
End Try
End Sub
.....
Private Sub cmdList_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdList.Click
RLIST_PARMS.size = Marshal.SizeOf(RLIST_PARMS)
RLIST_RESP.size = Marshal.SizeOf(RLIST_RESP)
RLIST_PARMS.ref_id_1 = edtRef1.Text & New String(Chr(0), 11 -
Len(edtRef1.Text))
RLIST_PARMS.hostname = edtHost.Text & New String(Chr(0), 101 -
Len(edtHost.Text))
RLIST_PARMS.system_user = "CHAINLNK" & New String(Chr(0), 101 - 8)
RLIST_PARMS.system_password = "CHAINLNK" & New String(Chr(0), 101 -
8)
RLIST_PARMS.system_select = edtStore.Text & New String(Chr(0), 11 -
Len(edtStore.Text))
RLIST_PARMS.target_name = edtStore.Text & New String(Chr(0), 11 -
Len(edtStore.Text))
RLIST_PARMS.proc_status_code = "REA" & New String(Chr(0), 4 - 3)
RLIST_PARMS.source_name = edtSource.Text & New String(Chr(0), 11 -
Len(edtSource.Text))
Dim cb As New ListDelegate(AddressOf RLIST_POPULATE)
---> rlist(RLIST_PARMS, RLIST_RESP, cb) <--- Errors here
Module 1
Public Declare sub rlist Lib "remotapi.dll" (ByRef RLIST_PARMS As
TRLIST_PARMS, ByRef RLIST_RESP As TRLIST_RESP, ByVal incb As ListDelegate)

Jan 15 '06 #1
9 4043
"Bob Simoneau" <bo*********@newsgroups.nospam> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
I am calling an c dll function which has a callback. The callback gets I end up with the same error. Any ideas would be appreciated. Thanks


I believe you should include an additional attribute on your declaration:

UnmanagedFunctionPointerAttribute(CallingConventio n.Cdecl)

Tim
Read my tech blog:
http://www.itwriting.com/blog
Jan 15 '06 #2
To which declaration: The help files are somewhat useless with
UnmanagedFunctionPointerAttribute(CallingConventio n.Cdecl)
"Tim Anderson" <ti*****@nospam.hotmail.com> wrote in message
news:O1**************@TK2MSFTNGP15.phx.gbl...
"Bob Simoneau" <bo*********@newsgroups.nospam> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
I am calling an c dll function which has a callback. The callback gets

I end up with the same error. Any ideas would be appreciated. Thanks


I believe you should include an additional attribute on your declaration:

UnmanagedFunctionPointerAttribute(CallingConventio n.Cdecl)

Tim
Read my tech blog:
http://www.itwriting.com/blog

Jan 15 '06 #3
Hi Bob,

Here is a link may help you.
http://www.msnewsgroups.net/group/mi...uages.csharp/t
opic15209.aspx

Because without source code, it is hard to troubleshoot such P/Invoke issue.
If that still did not work for you, I suggest you try to contact MSPSS
directly.
http://support.microsoft.com

Thanks for your understanding!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 16 '06 #4
I am almost 100% sure the problem is with the calling convention. How to
define a delegate with Cdecl calling convention in VB.NET?
""Peter Huang" [MSFT]" <v-******@online.microsoft.com> wrote in message
news:EJ**************@TK2MSFTNGXA02.phx.gbl...
Hi Bob,

Here is a link may help you.
http://www.msnewsgroups.net/group/mi...uages.csharp/t
opic15209.aspx

Because without source code, it is hard to troubleshoot such P/Invoke
issue.
If that still did not work for you, I suggest you try to contact MSPSS
directly.
http://support.microsoft.com

Thanks for your understanding!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no
rights.

Jan 16 '06 #5

"Bob Simoneau" <bo*********@newsgroups.nospam> wrote in message
news:eE*************@tk2msftngp13.phx.gbl...
To which declaration: The help files are somewhat useless with
UnmanagedFunctionPointerAttribute(CallingConventio n.Cdecl)


On the declaration of the delegate.

Tim
Read my tech blog:
http://www.itwriting.com/blog
Jan 16 '06 #6
I can not find a way to do that
(UnmanagedFunctionPointerAttribute(CallingConventi on.Cdecl)) n vb.net for
the delegate.

"Tim Anderson" <ti*****@nospam.hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...

"Bob Simoneau" <bo*********@newsgroups.nospam> wrote in message
news:eE*************@tk2msftngp13.phx.gbl...
To which declaration: The help files are somewhat useless with
UnmanagedFunctionPointerAttribute(CallingConventio n.Cdecl)


On the declaration of the delegate.

Tim
Read my tech blog:
http://www.itwriting.com/blog

Jan 16 '06 #7
"Bob Simoneau" <bo*********@newsgroups.nospam> wrote in message
news:uI****************@TK2MSFTNGP12.phx.gbl...
I can not find a way to do that
(UnmanagedFunctionPointerAttribute(CallingConvent ion.Cdecl)) n vb.net for
the delegate.


Something like this:

<UnmanagedFunctionPointer(CallingConvention.Cdecl) > _

Public Delegate Sub MyDelegate(ByRef RLISTSYS_DETAIL As TRLISTSYS_DETAIL)

Tim

Background worker exceptions in .NET 2.0

http://www.itwriting.com/blog/?postid=276
Jan 16 '06 #8
Thank you so much for your help. That worked perfectly. This was a real
challenge for me, but thanks to people like you and Peter Huang from
Microsoft Online Partner Support, I survived.

"Tim Anderson" <ti*****@nospam.hotmail.com> wrote in message
news:uq**************@tk2msftngp13.phx.gbl...
"Bob Simoneau" <bo*********@newsgroups.nospam> wrote in message
news:uI****************@TK2MSFTNGP12.phx.gbl...
I can not find a way to do that
(UnmanagedFunctionPointerAttribute(CallingConven tion.Cdecl)) n vb.net for
the delegate.


Something like this:

<UnmanagedFunctionPointer(CallingConvention.Cdecl) > _

Public Delegate Sub MyDelegate(ByRef RLISTSYS_DETAIL As TRLISTSYS_DETAIL)

Tim

Background worker exceptions in .NET 2.0

http://www.itwriting.com/blog/?postid=276

Jan 16 '06 #9
Hi Bob,

I am glad to hear that.
And thanks for Tim's knowledge sharing in the community.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 17 '06 #10

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

Similar topics

1
by: hemoji | last post by:
Hi, I'm developing a win32 dll in VC++, I have a thread running continuously in the dll to check for some input on socket, once it finds a input the data is required to be passed to the VB app...
2
by: MR | last post by:
help! I have an unmanaged DLL that I do not have the source code, so i can't recompile or make changes. the DLL requires a callback function. I would like to implement the callback method in a...
4
by: Jim Hammond | last post by:
It would be udeful to be able to get the current on-screen values from a FormView that is databound to an ObjectDataSource by using a callback instead of a postback. For example: public void...
6
by: ReinhardH | last post by:
Hi, I have to use a cdecl dll (3 party dll). One of the functions needs a callback as a parameter. Unfortunately it seems that I'm not able to solve this issue. What I have done is: Declare...
0
by: FishingScout | last post by:
I am re-writing an MS VC++ 6.0 application in Visual Studio 2005 VB.NET. In order for my new application to communicate with some hardware (an RFID reader) I need to communicate with a DLL that...
4
by: FishingScout | last post by:
I am re-writing an MS VC++ 6.0 application in Visual Studio 2005 VB.NET. In order for my new application to communicate with some hardware (an RFID reader) I need to communicate with a DLL that...
5
by: sajin | last post by:
Hi All.. We are using VB .Net 2005 for implementing an API. API needs to generate events. For this client wants us to use Windows Callback (delegate implementation). The intention of using...
9
by: Matthew Page | last post by:
Background - I'm trying to expose a C++ API to Visual Basic. I have access the the API source, but for this question assume that I don't. To do this I am using a wrapper DLL that just calls the...
2
by: KWhat4 | last post by:
I seem to have an issue that I cant resolve. I have a jni dll that calls SetWindowsHookEx with a callback to HookKeyboardProc (basically a real simple global keyboard hook). Now the dll almost...
1
by: FordPrefect | last post by:
I am using a 3rd party dll (not COM). One of the dll functions requires a callback function. I have used either DllImport or Declare to properly (I think) declare the function. The function...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.