473,503 Members | 1,849 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[VB6 to VB.net] Error in converting 'address of' to 'delegate'

1 New Member
Hello all,

I'm trying to upgrade a VB6 project into VB.net, and the problem I had is in converting 'address of' to 'delegate'.
I had the error "Value of type 'DelegateIDccManSink_OnLogIpAddr' cannot be converted to 'integer'.",
when calling this line, ReplaceVtableEntry(.., .., callbackOnLogIpAddr).

I guess the problem is due to the VB6 expected a memory address, but the 'delegate' doesn't return an address.

Any ideas are appreciated.


Expand|Select|Wrap|Line Numbers
  1.     Public Delegate Function DelegateIDccManSink_OnLogIpAddr(ByVal this As KwyDccMan.IDccManSink, ByVal dwIpAddr As Integer) As Integer
  2.  
  3.  
  4.     Public Sub DccManSinkInitialize(ByVal this As KwyDccMan.IDccManSink)
  5.  
  6.         Dim lObjAddress As Integer
  7.         Dim callbackOnLogIpAddr As DelegateIDccManSink_OnLogIpAddr
  8.  
  9.         ' Object Address
  10.         lObjAddress = ObjPtr(this)
  11.  
  12.         callbackOnLogIpAddr = New DelegateIDccManSink_OnLogIpAddr(AddressOf IDccManSink_OnLogIpAddr)
  13.  
  14.         ' Replace VTable Function Entries
  15.  
  16.         m_lFnOnLogIpAddr = ReplaceVtableEntry(lObjAddress, &H4S, callbackOnLogIpAddr)
  17.  
  18.     End Sub
  19.  
  20.     Private Function IDccManSink_OnLogIpAddr(ByVal this As KwyDccMan.IDccManSink, ByVal dwIpAddr As Integer) As Integer
  21.         IDccManSink_OnLogIpAddr = SCDCallParams(ObjPtr(this), EDccManCallID.eCallIDSink_OnLogIpAddr, dwIpAddr)
  22.     End Function
  23.  
  24.     ' Put the function address (callback) directly into the object v-table
  25.     Public Function ReplaceVtableEntry(ByVal lpObj As Integer, ByVal nEntry As Short, ByVal lpFunc As Integer) As Integer
  26.         ' lpObj - Pointer to object whose v-table will be modified
  27.         ' nEntry - Index of v-table entry to be modified
  28.         ' lpFunc - Function pointer of new v-table method
  29.  
  30.         Dim lpFuncOld As Integer, lpVTableHead As Integer, lpFuncTmp As Integer, nOldProtect As Integer
  31.  
  32.         ' Object pointer contains a pointer to v-table--copy it to temporary
  33.         CopyMemory(lpVTableHead, lpObj, 4)          
  34.         ' Calculate pointer to specified entry
  35.         lpFuncTmp = lpVTableHead + (nEntry - 1) * 4
  36.  
  37.         ' Save address of previous method for return
  38.         CopyMemory(lpFuncOld, lpFuncTmp, 4)        
  39.  
  40.         ' Ignore if they're already the same
  41.         If lpFuncOld <> lpFunc Then
  42.             ' Need to change page protection to write to code
  43.             VirtualProtect(lpFuncTmp, 4&, PAGE_EXECUTE_READWRITE, nOldProtect)
  44.  
  45.             ' Write the new function address into the v-table
  46.             CopyMemory(lpFuncTmp, lpFunc, 4)      ' *lpFuncTmp = lpFunc;
  47.  
  48.             ' Restore the previous page protection
  49.             VirtualProtect(lpFuncTmp, 4, nOldProtect, nOldProtect)    'Optional
  50.         End If
  51.  
  52.         ReplaceVtableEntry = lpFuncOld
  53.  
  54.     End Function
Oct 8 '08 #1
0 1366

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2833
by: john | last post by:
Hello, I am trying to convert a project from vb6 to vb.net. The code is a sample from an sdk for Canon digital camera's. I have gotten most of the issues resolved, but there are some that I am...
3
2491
by: BoloBaby | last post by:
OK, here's the problem... I have a digital input/output card that exposes IRQs (digital input change-of-state) through a DLL function. In VB6.0, I can use this ability through code that looks...
3
7895
by: BoloBaby | last post by:
OK, I've managed to clarify my question (whew). I'll show two blocks of code - one in VB6.0 and one in VB.NET. The VB6.0 code manages to execute the callback function, the VB.NET does not. The...
6
3980
by: Michael Turner | last post by:
Hi guys I am having the following problem upgrading a vb6 application, I have click the link as it suggested and I have search the net only to become even more confussed! HELP!!! Error: - ...
0
1204
by: damianmatiasmax | last post by:
Helow, Good days. I am creating a class Base in VB.NET, then I use this class base to create to the class son across inherits, and Then generate the object COM this class son to be used in VB6....
9
2538
by: Terry | last post by:
I am converting (attempting) some vb6 code that makes vast use of interfaces. One of the major uses is to be able to split out Read-only access to an obect. Let me give you a simple (contrived)...
5
2114
by: redeagle | last post by:
In VB6, the code for a structure is Structure zFuheader Dim Id1(80) As Byte Dim Id2(80) As Byte End Structure However, in .NET, it doesn't let you declare the array size in the structure.
3
1798
by: Dhananjay | last post by:
Hi All, I am facing problem when i am converting C#.net code(Delegate concept) into vb.net. I am unable to do that . Can someone help me to solve the problem. I am providing my C#.net code. ...
1
1777
by: =?Utf-8?B?TWlrZSBN?= | last post by:
Hi, My conversion seems from VB6 to VB.Net of an interface to an API seem to have gone OK, but when I look at the output from the Debug.Print("Active server is " & xmlServerActive) statement,...
0
7093
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
7287
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
7348
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...
1
7006
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
7467
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...
1
5021
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...
0
3175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3166
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1519
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 ...

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.