Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I convert C# to VB.net ? 1

Status
Not open for further replies.

TekMem

Programmer
Jul 23, 2004
98
CA
I have declaration in c#...I don't know how can I write same thing in vb.net

[DllImport("dmscli.dll", CharSet=CharSet.Unicode)]
public static extern bool aaApi_GetDatasourceHandlesByName ( string lpcwstrName, /* i Datasource name */
out IntPtr[] pDatasource, /* o Datasource handles */
out uint pulCount /* o Datasource handles count */);

Need help.
Thanks!
 
Search for Declare in VS help, it explains in detail how to use it.

Hope this helps.

[vampire][bat]
 
Thanks.I have tried declaration in vb.net is:


<DllImport("dmscli.dll", CharSet:=CharSet.Unicode)> _
Public Shared Function aaApi_GetDatasourceName(ByVal iIndex As Integer) As String
End Function
<DllImport("dmscli.dll", CharSet:=CharSet.Unicode)> _
Public Shared Function aaApi_GetDatasourceHandlesByName(ByRef lpcwstrName As String, _
ByRef pDatasource As IntPtr(), ByRef pulCount As UInt32) As Boolean
End Function

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim i As Integer

Dim count As Integer = pwdll.aaApi_SelectDatasources()
i = 0
Do While i < count
Console.WriteLine(pwdll.aaApi_GetDatasourceName(i))
ComboBox1.Items.Add(pwdll.aaApi_GetDatasourceName(i))
i += 1
Loop

End Sub

Output window shows what I want
MSSVRPP:pWPROD
ntsvrAA:pwT920

But result in combobox1 has funny characters in beginning of name of data sources.(i.e. it has some characters instead of MS and nt)

Also When I exit the program it gives error:
'System.ExecutionEngineException'

If I comment out combo box line it works fine.I am not sure what is going wrong here. also I am not clear enough if my declaration is right
 
Well TekMem,

Looking at the C# code (assuming that code works, and my understanding of C# is correct) it seems that lpcwstrName is a string - and NOT being passed by reference like the other two parameters as designated by the out keyword, which means your VB declaration you tried should look like this:

Code:
<DllImport("dmscli.dll", CharSet:=CharSet.Unicode)> _
    Public Shared Function aaApi_GetDatasourceHandlesByName(ByVal lpcwstrName As String, _
    ByRef pDatasource As IntPtr(), ByRef pulCount As UInt32) As Boolean
    End Function

But that's just for that function. Those characters you are seeing are probably non-printable characters that the combobox can't display so it puts some funny stuff in there, but the console window probably just filters out. I would compare the Length of returned string from aaApi_GetDatasourceName(i).Length() with what you can physically count via the window and/or the combobox to see if anything matches.
 
Thanks Borvik!
The length it shows is same 14. what it should be.
console window
MSSVRPP:pWPROD
ntsvrAA:pwT920
it shows in listbox or combobox something similar to as stated below
||SVRPP:pWPROD
|o'|o'rAA:pwT920
I guess there is some coversion problem ANSI characters. I am not that strong in dotNet + I am trying to use dll first time. some thing is going wrong...some where.There is some thing called Marshal. I do not know if I need to use that.
 
Here's an idea - instead of going directly to a combobox via
Code:
ComboBox1.Items.Add(pwdll.aaApi_GetDatasourceName(i))
how about assigning the value to a string, which gets added to the combobox:
Code:
Dim str As String
str = pwdll.aaApi_GetDatasourceName(i)
ComboBox1.Items.Add(str)
 
Thanks Borvik. I have figured out that problem after wasting a lot of time.
now i am trying this
Code:
<DllImport("dmscli.dll", CharSet:=CharSet.Unicode)> _
    Public Shared Function aaApi_Login(ByVal lDsType As Integer, _
   ByVal lptstrDataSource As String, _
   ByVal lpctstrUser As String, _
   ByVal lpctstrPassWord As String, _
   ByVal lpctstrSchema As String) As Boolean

    End Function
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ds_name As String = "abcR09:PWPROD"
        Dim user_name As String = "abc"
        Dim password As String = "123"
                If pwdll.aaApi_Login(pwdll.AAAPIDB_ODBC, _
        ds_name, user_name, password, [b]Nothing[/b]) Then
            MsgBox("kdkdk")
        Else
            Dim errorId As Integer = pwdll.aaApi_GetLastErrorId()

            Console.WriteLine("ErrorID" & (errorId))

            Console.WriteLine("ErrorID" & pwdll.aaApi_GetMessageByErrorId(errorId))

        End If
    End Sub

In the above codes every information seems to be ok. Only the problem seems to be at Schema. I have used Nothing vbnull and " " nothing to be seems to be ok. c# Null was used but vb doesnot support null.
It goes to else & Error message says "Invalid parameter passed to the API function."
If u have any clue then...big thaaanks in advance.

 
While C# uses the keyword Null - in VB its Nothing.
 
Nothing is not working...and other info dbname,ID, Password everything seems to be ok. AAAPIDB_ODBC is const.
 
Hmm...

What is the C# for aaApi_Logon declaration?
 
Here is declaration for c#
Code:
[DllImport("dmscli.dll", CharSet=CharSet.Unicode)] 
		public static extern bool aaApi_Login(
			int lDsType,
			string lptstrDataSource, 
			string lpctstrUser, 
			string lpctstrPassWord,
			string lpctstrSchema
			);
private string DatasourceName;
private string user_name;
private string password;
datasource_name = textBox3.Text;
			user_name = textBox1.Text;
			password = textBox2.Text;
			if ( PWAPI.aaApi_Login(PWAPI.AAAPIDB_ODBC, 
				datasource_name, 
				user_name, 
				password,
				null )
 
Hmmm....

Declaration looks good.

You said "Invalid parameter passed to the API function." - it's possible it doesn't mean the Nothing parameter, but rather another parameter your passing.

What is the declaration of AAAPIDB_ODBC for both C# and VB?
 
Constant
c#
public const int AAAPIDB_ODBC = 2;
mine
Public Const AAAPIDB_ODBC As Integer = 2
 
Looks good - I was thinking maybe it was an integer with a hex assigned to it.

The only other thing I can think of is the Datasource name being passed too it.

Earlier you mentioned that the console spit out the names of several datasources:
console window
MSSVRPP:pWPROD
ntsvrAA:pwT920

More recently when doing the logon you explicitly tell the program what datasource:
Dim ds_name As String = "abcR09:pWPROD"
Dim user_name As String = "abc"
I'm assuming your not actually using abcR09:pWPROD in the actual program, and just covering it on the boards here, but are you using the exact same string you saw in the console window from before? If not, it could be because that datasource doesn't exists.

Then again - it could be that the datasource being passed to the logon function is not in the proper format.
 
No that is not the problem. I am entering the right data source and it 100% exists. According to me it is Nothing. I mean "Nothing" the Schema which is coming in my way. and this is a part of my learning...
 
Schema which is coming in your way? The schema looks like it is a passed value - not a returned value (VB "ByVal name" instead of "ByRef name", C# "string name" instead of "out string name"). I could just be miss-reading that statement.

I'm also assuming the C# code for aaApi_Logon works.

I've run out of ideas there - maybe someone else that has worked with that dll would know more.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top