0

I have DLL function which has two string parameters and two int parameters. The function returns a string. When I call the function directly from excel, it is OK, but when I call the function from VBA, to DLL function is pass string params, which is not corresponding with original (nonsense characters). And function return string, witch have every seconds char " ".

My dll function looks like this:

BSTR __stdcall getPattern(int sex, int pad, BSTR * a, BSTR * b){
    ...
}

Declare function in VBA:

Declare Function GetPattern _
Lib "myPathToFunction" Alias "GetPattern" (ByVal poh As Integer, ByVal pad As Integer, ByRef a As String, ByRef b As String) As String

In excel I call the function like this: (And it is OK)

=GetPattern(I5;C1;A1;B1)

And from VBA call function like this: (and it return only first char of string)

result = GetPattern(Range("I5").Value, Range("C1").Value, Cells(i, 1).Value, Cells(i, 2).Value)

1 Answer 1

0

This could be an issue with VB converting strings to ANSI on C calls. You may need to explicitly pass a string pointer:

Dim param_a As String
Dim param_b As String

param_a = Cells(i, 1).Value
param_b = Cells(i, 2).Value
result = GetPattern(Range("I5").Value, Range("C1").Value, _
                    StrPtr(param_a), StrPtr(param_b))
Sign up to request clarification or add additional context in comments.

1 Comment

This get same result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.