convert to C#

  • Thread starter Thread starter pcPirate
  • Start date Start date
P

pcPirate

Hi,

Can anyone help me to convert the following VB6 code into C#???

Declare Function SQLSetConnectOption Lib "ODBC32.DLL" (ByVal hDbc As Long,
ByVal iOption As Integer, ByVal lValue As Long) As Integer

Thanks in advance
pcPirate
 
Here is some code that I used to import some Win32 functions from a Kernel32.Dll. I would suspect you could use the same code (obviously modified) to solve your problem:

internal class Kernel32
{
[DllImport("kernel32.dll", SetLastError=true )]
public static extern int GetPrivateProfileString( string szApplicationName,
string szKeyName, string szDefault, StringBuilder szReturnValue, int nSize, string szFilename );
[DllImport("kernel32.dll", SetLastError=true )]
public static extern int GetPrivateProfileSectionNames( byte[] lpszReturnBuffer,
int nSize, string szFilename );
}

Maybe something like:
internal class ODBC32
{
[DllImport("kernel32.dll", SetLastError=true )]
public static extern short SQLSetConnectOption ( int hDbc, short iOption, int lValue);
}

Don't forget that the data types are differenent between c/c++ and c#. C#int = c++long

Good Luck,
Kevin
 
Declare Function SQLSetConnectOption Lib "ODBC32.DLL" (ByVal hDbc As Long,
ByVal iOption As Integer, ByVal lValue As Long) As Integer

Ug. I am not up on VB6, but I'll give it a shot:

public int SQLSetConnectOption( long hDbc, int iOption, long lValue )
{
...
return someInt;
}

I don't know what that "ODBC32.DLL" is for, but maybe you can work it in
there somehow. Also, I assumed the function was public, but you can change
it to protected or private if need be. Lastly, it looks like a forward
declaration of a function (a function prototype), but those aren't used in
C#, so you'll have to include the function's code with the function
declaration.

Good luck! :^)
 
Okay, thanks guy

another favour pls...
how do you change this from VB6 into c#

Dim rdoEnv As RDO.rdoEnvironment
Dim rdoEnvs As RDO.rdoEnvironments

' Set the RDO environment
Set rdoEnvs = rdoEngine.rdoEnvironments
Set rdoEnv = rdoEnvs(0)

(Ya, this is rdo, hee hee... pls help....)

Thanks in advance.
pcPirate

Arvid Blandhol said:
using System.Runtime.InteropServices;
[DllImport("ODBC32.DLL")]
static extern int SQLSetConnectOption(UInt32 hDbc, int iOption, UInt32
lValue);

See the following MSDN Magazine article for more info:
http://msdn.microsoft.com/msdnmag/issues/03/07/NET/
...
Arvid

pcPirate said:
Hi,

Can anyone help me to convert the following VB6 code into C#???

Declare Function SQLSetConnectOption Lib "ODBC32.DLL" (ByVal hDbc As Long,
ByVal iOption As Integer, ByVal lValue As Long) As Integer

Thanks in advance
pcPirate
 
Back
Top