Value changes when passing into a dll function

Recently I am try to consuming a function from a dll.

In my program, i have input "00160001"
The program take in the value and pop out a message "00160001"
then the program call a function from a dll. Another popup message was trigger
this time the message is "ÌÌ00160001"


What is going on with my program?

ÌÌ00160001 only appear when i call the function from a dll?

by the way, i am a C++ beginner

thanks in advance

You must be passing the ?string? to/from the dll incorrectly.

It's difficult to say what's going wrong without knowing what you're doing. Can you post code?
Hi,

Once I have received the input, I store value into a char[66] variable. And I converted it to _bstr_t.
I need to convert it so that I can store the value into a struct that is created by a colleague.

The value is correct throughout the source code in the .exe file that I have created, but however, the value changes once after I pass the value to a dll.

The code was quite long and messy. so is quite difficult for me to post it here.
The code was quite long and messy. so is quite difficult for me to post it here.

What we need here is the bit of code where the various variables are declared, where the function is called, where the char array is converted into a _bstr_t, and also how the function is declared. Plus anything else that's in the chain. e.g.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
    char input[66];

    // populate input somehow

    struct MyStruct
    {
        _bstr_t value;
        // other members
    };

    // etc

    MyStruct ms;
    ms.value = ???; // how is the conversion done?

    // etc

    dll_function(&ms);


where

__declspec(dllexport) void __cdecl dll_function(input);

Andy
Last edited on
Sorry, is actually copying

lstrcpy(ms.value,(char*)input)

Last edited on
You're using lstrcpy to copy from a char array to a _bstr_t?

Try (if ms.value is a _bstr_t and input is a char array)

ms.value = input;

Andy

PS The structure your colleague defined does have a _bstr_t member, yes? Or a BSTR?
Last edited on
I try to pass a char[] variable from my program to the dll.
and the messagebox popup in that dll seem to been having the same problem.

my program show "00160001"
the dll show "ÌÌ00160001"

Thanks Andy and Disch.
Anymore advise?
I am still stuck with the issue.
Thank you
Anymore advise?

Sorry, but I have no idea what is wrong.

You have not provided enough information for anyone to even attempt to diagnose the problem.

Andy

I have manage to overcome the problem by set the UNICODE. but after a day, the same problem arise.
Last edited on
Topic archived. No new replies allowed.