Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / November 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
harishashim@gmail.com - 09 Nov 2005 10:20 GMT
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
Larry Lard - 09 Nov 2005 10:46 GMT
> 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
[quoted text clipped - 8 lines]
> 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 :)

Signature

Larry Lard
Replies to group please

Ken Tucker [MVP] - 09 Nov 2005 11:12 GMT
Hi,

         I dont think int64 is supported in vb6.  A .net int32 is the same
as the vb6 long.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/vaco
nintegerdatatypes.asp


Ken
---------------------
>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
[quoted text clipped - 44 lines]
> Thanks in advance,
> Haris
Nick - 09 Nov 2005 14:28 GMT
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);
}

>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
[quoted text clipped - 44 lines]
> Thanks in advance,
> Haris
harishashim@gmail.com - 10 Nov 2005 02:34 GMT
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
Nick - 10 Nov 2005 15:24 GMT
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

> Thanks everyone.
>
[quoted text clipped - 37 lines]
> Thanks and regards,
> Haris

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.