|
|
Hi, everybody. I'm a little stuck. I have no experience with DLL's and I'm trying to make something with'em.
I'm programming a dll (that calls a windows dll) wich contains the functions I want to use in my app. It compiles fine. But when I build my program that uses my dll, I get the next linking stage error:
MyProgram.obj : error LNK2001: unresolved external symbol "public: unsigned short __thiscall CMyProgramApp::OpenFile(class CString)" (?OpenFile@MyProgramApp@@QAEGVCString@@@Z)
Little help?
Znx.
Did you checked your TCP/IP settings? Enabled cookies? D'you want this dog?
|
|
|
|
|
Hi,
OK, I could be wrong on this one but, in my dll experience, it's because it cant find a certain function. I think it is the function in the dll you wrote. I would say try including the dll into program thats calling the dll you wrote. Hope it works.
Regards
Programm3r
|
|
|
|
|
|
You application should link with that library. which means, in your Project Properties (Settings) give lib file of the DLL. e.g SampleDLL.lib
SaRath.
"Where I am from, there is no plan B. So, take advantage of today becuase tomorrow is not promised. - 50 Cent"
My Blog | Understanding State Pattern
|
|
|
|
|
u have to specify the lib file of that dll.
for that take project settings->Link tab
In the object/Library edit box give the name of the lib file. then try compiling.
nave
|
|
|
|
|
I have the following piece of code.
char* strFile = new char[50] ;<br />
CString str( "Hello\nCoders" ) ;<br />
strFile = str.GetBuffer( str.GetLength() );<br />
std::ofstream myfile;<br />
myfile.open ("d:\\example.txt");<br />
myfile << strFile ;<br />
myfile.close() ;<br />
delete[] strFile ;
The program throws a Debug assertion error at delete[] strFile ; . The function throwing the Exception is _CrtIsValidHeapPointer(pUserData) .
I was of the impression that creation with new must be followed by cleanup with delete . Seems like I am wrong or I did something wrong in the above code. Can anyone explain?
---
Hakuna-Matada
It means no worries for the rest of your days...
It's our problem free, Philosophy
<marquee behavior="alternate" scrollamount="5" scrolldelay="50">
|
|
|
|
|
Hakuna-Matada wrote: char* strFile = new char[50] ;
strFile = str.GetBuffer( str.GetLength() );
when the scope of the variable ends, the destructor of the CString variable will be called. as per the implemantation of CString if you call GeBuffer, you should call ReleaseBuffer before calling any other functoins in CString else it will throw a debug asertion. Here the destructor itself a "silent" function. Hope you clear
SaRath.
"Where I am from, there is no plan B. So, take advantage of today becuase tomorrow is not promised. - 50 Cent"
My Blog | Understanding State Pattern
|
|
|
|
|
In addition to what sarath said
char* strFile = new char[50] ;
strFile = str.GetBuffer( str.GetLength() ); causes a memory leak.
char* strFile = 0;
strFile = str.GetBuffer( str.GetLength() );
this is enough. And dont call delete.
nave
|
|
|
|
|
In addition to Naveen said,
Use GetBuffer only if you are doing some modifications on the CString.
operator LCTSTR (const char*) has been overloaded in CString for reading purpose.
SaRath.
"Where I am from, there is no plan B. So, take advantage of today becuase tomorrow is not promised. - 50 Cent"
My Blog | Understanding State Pattern
|
|
|
|
|
Hi. Thanks for your reply. Well now I have..
char* strFile = new char[50] ;<br />
CString str( "Hello\nCoders" ) ;<br />
strFile = str.GetBuffer( str.GetLength() );<br />
str.ReleaseBuffer() ;<br />
std::ofstream myfile;<br />
myfile.open ("d:\\example.txt");<br />
myfile << strFile ;<br />
myfile.close() ;<br />
delete[] strFile ;
but it still doesn't work. As you may have noticed, I used the ReleaseBuffer as you had suggested but to no avail. Am I doing something wrong?
---
Hakuna-Matada
It means no worries for the rest of your days...
It's our problem free, Philosophy
<marquee behavior="alternate" scrollamount="5" scrolldelay="50">
|
|
|
|
|
why you are using the same buffy code?
This will work fine...
CString str( "Hello\nCoders" ) ;
std::ofstream myfile;
myfile.open ("d:\\example.txt");
myfile << (LPCTSTR)str;
myfile.close() ;
SaRath.
"Where I am from, there is no plan B. So, take advantage of today becuase tomorrow is not promised. - 50 Cent"
My Blog | Understanding State Pattern
Last modified: Wednesday, August 02, 2006 1:15:50 AM --
|
|
|
|
|
Thanks for your time. Now I understand.
---
Hakuna-Matada
It means no worries for the rest of your days...
It's our problem free, Philosophy
<marquee behavior="alternate" scrollamount="5" scrolldelay="50">
|
|
|
|
|
Make sure you call ReleaseBuffer after a GetBuffer or GetBufferSetLength.
This works:
<br />
CString str( "Hello\nCoders" ) ;<br />
std::ofstream myfile;<br />
myfile.open ("c:\\example.txt");<br />
myfile << str.GetBuffer( str.GetLength() ) ;<br />
str.ReleaseBuffer();<br />
myfile.close() ;<br />
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Steve Echols wrote: myfile << str.GetBuffer( str.GetLength() ) ;
In this code, it's not doing any editing. So that we can simply use the string object like this
myfile << (LPCTSTR) str;
SaRath.
"Where I am from, there is no plan B. So, take advantage of today becuase tomorrow is not promised. - 50 Cent"
My Blog | Understanding State Pattern
|
|
|
|
|
You are correct sir. I think I was just trying to stress the ReleaseBuffer call if you call GetBuffer.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
|
You are first allocated a buffer on the heap, of size 50. You store the pointer in strFile. Then you do a CString::GetBuffer on a CString object, and overwrite the value in strFile with this new value, thus creating a storage leak.
Also, there is no need for the parameter to GetBuffer.
When you call delete, which frees the CString buffer out
from under the CString, then the CString destructor sees a completely screwed-up heap.
LPTSTR strFile = str.GetBuffer();
std::ofstream myfile;
myfile.open ("d:\\example.txt");
myfile << strFile ;
myfile.close() ;
Amar
|
|
|
|
|
You're misusing the return value of GetBuffer() . GetBuffer() returns a pointer to the buffer that the CString manages, you must not delete that pointer.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
Hi
i am developing a Dialog based application in VC++ MFC, i need to provide multi-language support to that application. can any one provide me some solution to that.
Thanks in advance for any help.
Gopinath MV
|
|
|
|
|
gloriousgopi wrote: multi-language support to that application
You can UNICODE
Do your Duty and Don't expect the Result
|
|
|
|
|
Thanks for u suggestion.
Can you plz explain it some more. So that i can able to work on it
Gopinath MV
|
|
|
|
|
|
My problem is to provide multilanguage support for my application.
i,e i have to show the Dialog based application in English when the user clicks english from the menu, or in French when he clicks French from the menu.
when the user changes the language the application should change its whole display according to user choice
Gopinath MV
|
|
|
|
|