Difficulties in using .Net dll in VB6 due to Int64 type in function parameters

H

harishashim

I have gone through necessary step and have been able to use a .Net
libraries (created using C#) in VB6. It run good untill I try to use
certain function in the library that is using Int64 type as parameter.

VB6 give the following error

Compile Error:
Function or interface marked as restricted, or the function use an
automation type not supported in Visual Basic.

There must be something that can be done either on C# side or VB6 side.
Please advise.

Here is some code (not exactly but modified here and there)

IN C#
=====================================================

public interface ITesting
{

bool TestConnect(string strc, string usr, string pwd);
void TestDisconnect();
bool Start(bool boolparam);
bool TestCheck(Int64 param1, Int64 param2);

}

//bla bla bla
....

public class Testing : ITesting
{
//bla bla bla
...

public bool TestCheck(Int64 param1, Int64 param2)
{
//bla bla bla
...
}

//bla bla bla
...
}


Thanks in advance,
Haris
 
L

Larry Lard

I have gone through necessary step and have been able to use a .Net
libraries (created using C#) in VB6. It run good untill I try to use
certain function in the library that is using Int64 type as parameter.

VB6 give the following error

Compile Error:
Function or interface marked as restricted, or the function use an
automation type not supported in Visual Basic.

There must be something that can be done either on C# side or VB6 side.
Please advise.

Try using the Currency type on the VB6 side. If it does work, you will
have to go through fun and games with CopyMemory and the like to get
64-bit integer values into and out of the Currency.

Credit to Bruce McKinney if it works :)
 
N

Nick

If you can change the .dll as you suggest, you can create an overloaded
function that uses 2 longs..
i don't claim this is syntactilcy correct...but basicly you want: something
like

public void function VBFriendly(int high32bits, int low32bits)
{
// call the
ulong x = (high32bits << 32) + low32bits;

VBUnfriendly(x);
}
 
H

harishashim

Thanks everyone.
From the replies I can summarize that either change VB code by
converting Int64 to Currency or something else useable by VB or create
another function in C# dll that expose int to VB yet call the function
with Int64 parameters.

Actually I am trying to avoid both solution. I was thinking more in the
line of changing the ITesting interface declaration.

I have tried to do this:

public interface ITesting
{

bool TestConnect(string strc, string usr, string pwd);
void TestDisconnect();
bool Start(bool boolparam);

//bool TestCheck(Int64 param1, Int64 param2);
bool TestCheck(int param1, int param2);

//Int64 TestID{get;}
int TestID{get;}
}

There is two error:

'Testing' does not implement interface member 'ITesting.TestCheck(int,
int)'

'Testing' does not implement interface member 'ITesting.TestID'.
'Testing.TestID' is either static, not public, or has the wrong return
type.

I can understand why the error is given. Just wondering is there a work
around for this? If this cannot be done appreciate some explanation on
why it cannot be done.

Thanks and regards,
Haris
 
N

Nick

Haris,

Since you changed your interface, you will also need to change the class
that implements it. If you can't change that class, you will need to change
the interface back to what it was before, and find another work around.

Assuming you CANNOT change the class and interface to be VB friendly (either
by modifying existing calls, or adding new ones), I think your only option
would be to create a small helper .dll in C# to make the call for you. To
tell the truth, I've not created a C# dll to be compatable with VB 6... but
here's the meat of it...esentially the same suggestion I mentioned earlier,
but now using your parametrs

[whatever attributes necessary to make COM compliant]
class ITestingVB6Adapter
{
[whatever attributes necessary to make COM compliant]
public bool TestCheck(
ITesting testing, // testing object to make the call against
int param1_hi, // high-order 32 bits of 64 bit param1
int param1_lo, // low-order 32 bits of 64 bit param1
int param2_hi, // high-order 32 bits of 64 bit param2
int param2_lo) // low-order 32 bits of 64 bit param2
{
Int64 param1;
Int64 param2;

param1 = param1_hi; // assign high order bits
param1 = param1 << 32; // shift up
param1 = param1 + param1_lo; // add low order bits

param2 = param2_hi; // assign high order bits
param2 = param2 << 32; // shift up
param2 = param2 + param2_lo; // add low order bits

// return result of object method
return testing.TestCheck(param1, param2);
}
}


In VB you would call this passing your object and methods.

Dim oT As new ITesting
Dim oH As new ITestingVB6Adapter
Dim b as Boolean
Dim param1 As Long
Dim param2 As Long

param1 = 1234567
param2 = 7654321

// since VB Long's are 32 bit numbers, you can always pass 0 for high 32
bits
// if you need real 64 bit values, you will have to work out the math
somehow.
b = oH.TestCheck(oT, 0, param1, 0, param2)


Hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top