|
-
Feb 2nd, 2002, 11:02 AM
#1
Thread Starter
New Member
VB / C++ COM BSTR question
Not sure if this is more a VB or C++ question, posted on both.
I have a C++ dll with a function that is used
in VB code.
The C++ function returns a BSTR to the VB calling functions. This function is called ALOT by various VB function.
The problem:
After much processing (1 hour+), memory is consumed like crazy, 200M and up. We (the team that must debug this) think the BSTR's aren't being free'd in VB. We know this should be done automagically. I will test this theory today.
If that is the case how can we free the BSTR memory in the VB code. I only know of:
bstrVar = Nothing
or
bstrVar = ""
Could I create a method in the C++ class that returns the memory with SysFreeString? May get a pointer from the VB code as a func parameter?
any ideas are welcome.
-
Feb 2nd, 2002, 01:17 PM
#2
Fanatic Member
to free string mem in VB, just assign it a zero-length value
VB Code:
Dim myStr As String
myStr = "hello"
'free it
myStr = ""
i think in c++, you do
PHP Code:
char *mystring = new char[<maxlength>];
//free if
free (mystring)
i haven't use BSTR, so I wouldn't know..sorry
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Feb 2nd, 2002, 01:49 PM
#3
Take the return string as a parameter to the DLL function. That way, it is up to VB to create and delete the string.
Z.
-
Feb 3rd, 2002, 02:25 PM
#4
Monday Morning Lunatic
Code:
char *mystring = new char[<maxlength>];
//free if
free (mystring)
Ick ick ick 
Code:
char *mystring = new char[<maxlength>];
//free if
delete[] mystring;
Don't use free and new on the same pointer.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 3rd, 2002, 02:38 PM
#5
Fanatic Member
Try setting the object to nothing
So:
set obj = createobject("the.c++object")
ret = obj.thefunctioncall
set obj = nothing
this should free the c++ object.
Bye the way, the BSTR is only 65537 (In borland anyway) characters long so if you need any more you need to write this to a file.
My secretary hopes that I will pay her, her landlord hopes that she will produce some rent, the Electricity Board hopes that he will settle their bill, and so on. I find it a wonderfully optimistic way of life. [Dirk Gently]
-
Feb 3rd, 2002, 09:12 PM
#6
Fanatic Member
Originally posted by parksie
Code:
char *mystring = new char[<maxlength>];
//free if
free (mystring)
Ick ick ick 
Code:
char *mystring = new char[<maxlength>];
//free if
delete[] mystring;
Don't use free and new on the same pointer.
ah okay...maybe thats why...
i learned something today
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|