Click here to Skip to main content
15,887,083 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralRe: Weird problem using C++ dll from vb6 Pin
lenourien23-Aug-11 2:55
lenourien23-Aug-11 2:55 
GeneralRe: Weird problem using C++ dll from vb6 Pin
lenourien23-Aug-11 5:05
lenourien23-Aug-11 5:05 
AnswerRe: Weird problem using C++ dll from vb6 Pin
MicroVirus23-Aug-11 5:24
MicroVirus23-Aug-11 5:24 
GeneralRe: Weird problem using C++ dll from vb6 Pin
Richard MacCutchan23-Aug-11 5:51
mveRichard MacCutchan23-Aug-11 5:51 
AnswerRe: Weird problem using C++ dll from vb6 Pin
MicroVirus23-Aug-11 5:18
MicroVirus23-Aug-11 5:18 
GeneralRe: Weird problem using C++ dll from vb6 Pin
lenourien23-Aug-11 13:33
lenourien23-Aug-11 13:33 
QuestionRe: Weird problem using C++ dll from vb6 Pin
MicroVirus23-Aug-11 15:22
MicroVirus23-Aug-11 15:22 
AnswerRe: Weird problem using C++ dll from vb6 Pin
lenourien24-Aug-11 4:17
lenourien24-Aug-11 4:17 
Hi again Microvirus. First of all I have to be very clear and say that you have in no way shape of form been harsh as far as I'm concerned. You're giving of your time to someone you don't know and you're doing it efficiently and nicely. Thank you.

Before I try to explain my code let me explain what I did and the problems I solved already following your advice. What you said about static variables staying around was a real eye opener so I got rid of all of them. The problem with the array not initialised befor used was easily solved by setting each value to 0 before use. I was concerned about having to use a for loop for that but there was already a for loop in which the array was involved so I just added the 0 there and it worked.

Actually I think I only have one problem left provided nothing else happens after I solve it.
So I'll explain my code and then I'll explain the problem.

What my code does is:
-type a list of words in vb
-send the list to the C++ dll
-c++ works with the word list, create a new list of words using part of the original list
-c++ also generate a string of characters and an int representing the number of words used from the original list
-c++ send the string and the int back to vb through a callback function
-c++ sends the modified word list back to vb through a return (the VT_ARRAY|VT_BYREF|VT_BSTR variable)

So as I said, now everything seems to work except for one last problen. during the second round, the list sent back to vb contains garbage characters and those characters have nothing to do with any characters I put in the list.

For example, the first time I use the list tata, toto, titi. The dll uses the whole list so it sends back tata, toto, titi. Then I try again and this time I send tata, toto, titi, tutu, tete. Once again the dll uses all of them and sends back the whole list but this time I get something like tata, totohh, titihtiti, tutu, tete.

So I think there is still something hanging around and I don't have any static around anymore.

So here is some things from my code

sorry for the very very long message

my dll receives the list from vb as a variable:
LPSAFEARRAY* StringArray

then I have:
char words[1000][26];
int  wordlen[1000];
char** StrPtr = 0;
long LowerBound = 0;
long UpperBound = 0;

SafeArrayGetLBound(*StringArray,1,&LowerBound);
SafeArrayGetUBound(*StringArray,1,&UpperBound);

SafeArrayAccessData(*StringArray, (void**)&StrPtr);

for(nr_words = LowerBound; nr_words <= UpperBound; ++nr_words)
    {
          strcpy(words[nr_words], StrPtr[nr_words]);
    }

    SafeArrayUnaccessData(*StringArray);


the array words's first dimension is now filled with the word list

then I have
C#
for(i = 0; i < nr_words; i++) {
         wordlen[i] = strlen(words[i]);

 }

so obviously wordlen is filled with the length of each word from the list.

after that when all the calculation is done and all I have:
LPSAFEARRAY pSA;
pSA= SafeArrayCreate(VT_BSTR,1,aDim);

if (pSA != NULL) {

BSTR element = SysAllocString((BSTR)words[low]);

unsigned int length = SysStringByteLen(element);
BSTR wcElement = NULL;

wcElement = SysAllocStringByteLen(NULL, length*2); 

MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,(LPCSTR)element
, -1, (LPWSTR)wcElement, length*2);

for(i = 0; i < wordcnt[low]; i++) {

	if (hr= SafeArrayPutElement (pSA, &arrIndex, wcElement)){
		SafeArrayDestroy(pSA); 
			}
	SysFreeString (wcElement); 
	SysFreeString (element);
	arrIndex++;
		
    }


This of course uses the word from the list and puts them in the safearray pSA.

and finally I use that safearray as I said already to send it back to vb.

It all works the first time.

I think that the problem comes from the
char** StrPtr = 0;
I have at the beginning and that allow me to put the list from vb inside the words[] array in c++.

I think that one needs to be released manually but I don't know how.

I might be wrong though.

Thanks again
AnswerRe: Weird problem using C++ dll from vb6 Pin
MicroVirus24-Aug-11 17:41
MicroVirus24-Aug-11 17:41 
GeneralRe: Weird problem using C++ dll from vb6 Pin
lenourien25-Aug-11 1:31
lenourien25-Aug-11 1:31 
GeneralRe: Weird problem using C++ dll from vb6 Pin
MicroVirus25-Aug-11 3:25
MicroVirus25-Aug-11 3:25 
GeneralRe: Weird problem using C++ dll from vb6 Pin
lenourien25-Aug-11 12:39
lenourien25-Aug-11 12:39 
QuestionWTSSendMessage fails as RPC Server is unavailable Pin
Arun Parthasarathy22-Aug-11 1:24
Arun Parthasarathy22-Aug-11 1:24 
AnswerRe: WTSSendMessage fails as RPC Server is unavailable Pin
Tony Richards25-Aug-11 13:05
Tony Richards25-Aug-11 13:05 
QuestionConverting ADO data types into C++ data types Pin
Bahram198420-Aug-11 0:47
Bahram198420-Aug-11 0:47 
AnswerRe: Converting ADO data types into C++ data types Pin
John Schroedl22-Aug-11 3:28
professionalJohn Schroedl22-Aug-11 3:28 
QuestionInheriting a template class Pin
Subin Mavunkal17-Aug-11 1:43
Subin Mavunkal17-Aug-11 1:43 
AnswerRe: Inheriting a template class Pin
George L. Jackson9-Sep-11 12:13
George L. Jackson9-Sep-11 12:13 
Questionc++ function name parameter problem Pin
ali_zdn14-Aug-11 3:11
ali_zdn14-Aug-11 3:11 
AnswerRe: c++ function name parameter problem Pin
Richard MacCutchan14-Aug-11 7:03
mveRichard MacCutchan14-Aug-11 7:03 
QuestionProject Converted From VS2003 to VS2008, get exception when call dialog.doModal Pin
Andraw Tang5-Aug-11 11:16
Andraw Tang5-Aug-11 11:16 
AnswerRe: Project Converted From VS2003 to VS2008, get exception when call dialog.doModal Pin
Richard MacCutchan5-Aug-11 22:32
mveRichard MacCutchan5-Aug-11 22:32 
GeneralRe: Project Converted From VS2003 to VS2008, get exception when call dialog.doModal Pin
Andraw Tang8-Aug-11 4:37
Andraw Tang8-Aug-11 4:37 
GeneralRe: Project Converted From VS2003 to VS2008, get exception when call dialog.doModal Pin
Richard MacCutchan8-Aug-11 7:02
mveRichard MacCutchan8-Aug-11 7:02 
GeneralRe: Project Converted From VS2003 to VS2008, get exception when call dialog.doModal Pin
Andraw Tang8-Aug-11 7:18
Andraw Tang8-Aug-11 7:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.