Link to home
Create AccountLog in
Visual Basic Classic

Visual Basic Classic

--

Questions

--

Followers

Top Experts

Avatar of TheAvenger
TheAvenger🇨🇭

Use of a 64 bit unsigned long parameter in a DLL
Hello guys

I have a DLL written in C++, which exports a DLL the following way:

bool __stdcall MyFunc(unsigned __int64 param1)

I need to use this in VB6. However VB6 does not have unsigned long type and I cannot find another 64 bit type that I can easily convert to. Any ideas?

TheAvenger

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of Erick37Erick37🇺🇸

You may be able to pass in a User Defined Type containing 2 Longs.

Avatar of TheAvengerTheAvenger🇨🇭

ASKER

I tried but it breaks the environment. I found a sentance saying:

You can pass an entire user-defined type as a single argument if you pass it by reference. User-defined types cannot be passed by value.

I think I need to pass it by value in order to work.

Try using Currency data type

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of TheAvengerTheAvenger🇨🇭

ASKER

Does not work either - crashes again.

Avatar of Erick37Erick37🇺🇸

How are you declaring the function?

Declare Function MyFunc Lib "MyDLL" (param1 As MyType) As Boolean

Avatar of TheAvengerTheAvenger🇨🇭

ASKER

When I try with MyType - yes. When I try with currency I tried:

Declare Function MyFunc Lib "MyDLL" (param1 As Currency) As Boolean

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of AzraSoundAzraSound🇺🇸

Yes, UDTs must be passed by reference from VB, so your C DLL would need to be looking for a pointer.

Avatar of TheAvengerTheAvenger🇨🇭

ASKER

I cannot change the C++ library :-((

Can you post the DLL for download?

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of Erick37Erick37🇺🇸

When you say "crashes" what do you mean?
Is there an error message?

Avatar of TheAvengerTheAvenger🇨🇭

ASKER

It tells me that an illegal operation was performed with the options to either end the application or debug it. When I select end it closes the whole IDE.

No, unfortunately the DLL is a property of the company :-((

Avatar of Erick37Erick37🇺🇸

There is always the option to make a bridge DLL which would make the transition from the VB UDT to the __int64.

Pass in the UDT to your bridge or wrapper C++ dll which converts it into an __int64 which in turn calls MyFunc with a true __int64.

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of TheAvengerTheAvenger🇨🇭

ASKER

Can you tell me how to convert a string (char* in C++) to __int64? This in C++. If I have this, I can make a help method which makes the transformation from string to __int64 and calls the original one

ASKER CERTIFIED SOLUTION
Avatar of Erick37Erick37🇺🇸

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of AzraSoundAzraSound🇺🇸

VB only supports signed data types, but as noted, it should not be an issue.  You just may need to write a routine to convert the value to something your unsigned parameter understands, e.g., a negative value.

Avatar of TheAvengerTheAvenger🇨🇭

ASKER

Hmm, with byval it succeeded to pass it. But I need 19 digit numbers and they do not fit in the currency type

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Try

LSet SomeValue = ReturlValue
Debug.Print SomeValue

Avatar of TheAvengerTheAvenger🇨🇭

ASKER

egl1044: What should be SomeValue/ReturnValue?

SOLUTION
Avatar of AzraSoundAzraSound🇺🇸

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.

Avatar of Erick37Erick37🇺🇸

You will need to use 2 Longs and then copy then into the Currency memory location.  It should work (in theory).

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)


    Dim c As Currency
    Dim hiWord As Long
    Dim loWord As Long
   
    hiWord = &H12345678
    loWord = &H87654321
   
    Call CopyMemory(ByVal VarPtr(c), hiWord, 4)
    Call CopyMemory(ByVal VarPtr(c) + 4, loWord, 4)

Now, c contains the 64 bit result

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of TheAvengerTheAvenger🇨🇭

ASKER

Sorry egl1044, missed your first post :-((
Please post here: https://www.experts-exchange.com/questions/21579889/A-question-for-egl1044.html
Visual Basic Classic

Visual Basic Classic

--

Questions

--

Followers

Top Experts

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.