How can I work around this problem?
I need to interface to a DLL (InhecoMTCdll.DLL from Inheco.com) that exposes in its API the function name 'WriteOnly()', which is a VB.NET reserved word.
The problem then is that my VB.NET windows forms app gets a build error when I declare the API.
Is there anyway to work around this? I don't have the source code for the DLL. I tried JetBrains dotPeek to decompile, but could not see how to re-compile.
API of InhecoMTCdll.DLL .......................
public int FindTheUniversalControl(
int ID);
public void WriteOnly(string msg);
public string ReadSync();
My declaration of API in my VB.NET Pro 2017 windows app....
Imports System.Runtime.InteropServices
Module Inheco_Thermoshake_interface
Public Class NativeMethods
' Function within DLL:
' Public int FindTheUniversalControl(int ID);
' which corresponds to VB.NET declaration:
<DllImport("InhecoMTCdll.dll")>
Public Shared Function FindTheUniversalControl(ByRef ID As Int32) As Int32
End Function
' Need to re-program DLL with Inheco_WriteOnly because WriteOnly is VB keyword.
' public void WriteOnly(string msg);
<DllImport("InhecoMTCdll.dll")>
Public Shared Sub WriteOnly(ByRef msg As Byte()) <<<<<<< BUILD ERROR: "KEYWORD IS NO VALID AS AN IDENTIFIER"
End Sub
' public string ReadSync();
<DllImport("InhecoMTCdll.dll")>
Public Shared Function ReadSync() As Byte()
End Function
End Class
End Module
You can use reserved word in VB.Net for function and variable names if you surround it with square brackets. For example:
Public Shared Sub [WriteOnly](ByRef msg As Byte())