|
What some of the other people have said makes sense.
However there is another way. I personally detest linking to the C runtime DLL, because it then means you have to redistribute MSVCRT.DLL.
ANy time I deal with objects going from DLL to a process or another DLL is to make sure that whoever allocated the object has the responsibility for deleting it. So if you are returning a string from a DLL, that string needs to be a static variable somewhere in the DLL, or the DLL needs to control it in some other form.
"When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity." - Albert Einstein
|
|
|
|
|
Navin wrote:
you have to redistribute MSVCRT.DLL
Shouldn't be an issue. In fact a number of MS system dll's link to it already e.g. odbc32.dll. So even if you don't use it directly chances are some sub-system is. If you can't beat 'em join 'em.
Navin wrote:
make sure that whoever allocated the object has the responsibility for deleting it
Exactly, however this is a case where he is using someone elses library i.e wstring. _If_ the implementation has this side-effect there is little he can do.
Personally, i've written my own class framework (built up over the last 14 yrs) that takes all of this (and more) into account and minimizes the dependency on the CRT - not a task to enter into lightly though.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
I'm trying to build two projects one a DLL and another an exe that uses the DLL.
Both projects have their code generation set to "Multi Threaded Debug"
Both have _UNICODE defined
both use the std::wstring class for strings
it seems that if I have a class member method that returns a wstring object, say
wstring Foo::getName(), in the DLL (and the class is exported),
that i get a crash in the exe after the function call ends (and the temporary wstring instance is cleaned up).
If I take the code in the method and simply cut and paste into the exe code that calls the dll's function, then the actual code itself works fine.
However if I switch the code generation to "Multi Threaded DLL Debug"
then everything works fine, no crashes at all!
Is there something funky about unicode strings that I am missing? Is this something else entirely? Have I just smoked too much crack?
Help!
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
|
|
|
|
|
Haven't looked at it, but run into similar bugs before.
It has always been the CRT (C RunTime Library).
What happens is because you are statically linking the CRT to both the DLL and the EXE there are 2 process heaps generated.
I would assume that std:wstring is allocating from one and trying to free/realloc in the other at some point via calls to malloc/realloc/free.
When you link CRT as dll in both DLL and EXE then only one process heap is generated.
Solutions :
1. As you have found link to CRT dll (this is what i've done). There are more reasons than just malloc/free, you would also have problems with fopen() files that are opened in the DLL won't be accessable in EXE. CreateFile() doesn't have this problem as the file structures are globally unique.
2. Write your own allocator for wstring that allocates from a new heap you create in the DLL (i do this as well).
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Achhh
This is so lame, I guess I never ran into this before because I would either statically link everything into one exe, or (for stuff at home) always use dll CRT.
You'd think there would be an easier way...
Oh well. I'll just stick with your suggestion 1!
Thanks
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
|
|
|
|
|
Jim Crafton wrote:
This is so lame
Yes, but what other choice is there ?
When you compile the EXE (w/ static CRT) it has no idea that you will be linking to a DLL that already has a static instance of CRT. You will have this problem when you try to statically link to any library - you get a copy of all the global variables.
Thinking about your problem some more ...
In general i wouldn't expect this problem as wstring is hidding all malloc/free calls, that is they are all done in the DLL against the DLL process heap.
The only way i could see this happening is if wstring has some inline methods that call malloc/realloc/free that you are calling in the EXE.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Hi,
In my SDI application, I have two different FormViews separated by a splitter window. I want the document class to handle the shared data between the two views.
How do I add the new view to the existing document class.
How the data among the two views is shared by the single document?
Please give an example.
Thanks
Binayak
|
|
|
|
|
>> add the new view to the existing document class.
In a member function of your document class:
CDocument::AddView(...)
>> How the data among the two views is shared by the single document?
Any way you want to in your design of your CDocument derived class. You can also say, the two views share their data using the document class.
"No matter where you go, there your are..." - Buckaoo Banzi
-pete
|
|
|
|
|
I'm adding a record to an Access database via ADO and then trying to query for that record based on the date:
m_addTime = COleDateTime::GetCurrentTime();
...
VARIANT v;
VariantInit(&v);
V_VT(&v) = VT_DATE;
V_DATE(&v) = m_addTime;
pRS->Fields->Item[_variant_t((long)1)]->Value = v;
This works fine, but querying for the time value has me stumped:
CString sql;
sql.Format("SELECT id, dtTime FROM tblSample WHERE dtTime = %f", (double)m_addTime);
pRS = m_pDB->ExecuteRS_ReadOnly(sql);
...returns no rows.
dtTime is a Date/Time value in the access table.
Any clues would be appreciated
|
|
|
|
|
>> CString sql;
>> sql.Format("SELECT id, dtTime FROM tblSample WHERE dtTime = %f", (double)m_addTime);
did you try taking the SQL string resulting from your concatenation and running it in Access?
"No matter where you go, there your are..." - Buckaoo Banzi
-pete
|
|
|
|
|
Good point. Yes, and it doesn't return a record either. I made sure that the field isn't defaulted or filtered in any way, just in case. I also tried this:
sql.Format("SELECT count(*) FROM tblSample WHERE dtTime = %f", (double)m_addTime);
this also returns a 0 in the resulting recordset. Next, I cleared the table, wrote a single record, read it back in (select *), and the before and after values were identical, yet the original sql still returns 0 records. This leads me to believe that there is a formatting problem, like somehow my double value is being truncated. I tried "%0.9f" with the same results.
thanks
|
|
|
|
|
Additionally, I am seeing this behaviour:
(field 1 is time field in previous sql)
COleDateTime dtTime(GetVariantDate(m_pRS->Fields->Item[_variant_t((long)1)]->Value, (DATE)0));
double dTime = GetVariantDouble(m_pRS->Fields->Item[_variant_t((long)1)]->Value,0);
dtTime.Format("%a, %m/%d/%Y") returns "Sat, 12/30/1899"
The original record in Access reads: 9/2/2003 4:31:24 PM
dTime reads: 0.68847222222222 (huh?)
NOTE: the GetVariant methods simply return the requested variant type or the default value which is the second argument.
Help!
|
|
|
|
|
You need to format your query time differently. You know it's implemented and stored as an 8-byte IEEE floating point, but Access won't admit it.
Try asking "SELECT id FROM tblSample WHERE dtTime = 'YYYY-MM-DD hh:mm:ss'" instead.
You can use VariantTimeToSystemTime to convert from the original value.
However, you should note that some databases (like SQL Server) will truncate at milliseconds, so it might be an idea to use VariantTimeToSystemTime, and convert back (SystemTimeToVariantTime), which ignores milliseconds, before inserting the value. This will prevent any off by a small fraction of a second errors.
Steve S
|
|
|
|
|
Steve,
Thanks that solved my problem. Just the change before the update did the trick!
daug
|
|
|
|
|
hello all..
i need some help to solve my problem..
i'd tried so many times to test this program...
it works very well if i did not include the FOR LOOP into my program.
i hope you guys can have a look at my program and figure out
what mistakes i did..thanks..
COLORREF OriginalPixelValue;
COLORREF NewPixelValuesss;
int PixelCount=0;
CoX=0; //coordinate-X
CoY=0; //coordinate-Y
for(int abcde=0; abcde<48; abcde++)
{
OriginalPixelValue=PixelValue(CoX,CoY);
NewPixelValuesss=(OriginalPixelValue | Data_0[PixelCount]) & Data_1[PixelCount];
GoWatermark(NewPixelValuesss,CoX,CoY);
PixelCount+=1;
if(CoX<m_bminfo1.bmwidth)
{
="" cox+="1;
" }
="" else
="" coy+="1;
" cox="0;
" <b="">}
COLORREF CThongThongThongDlg::PixelValue(unsigned int cox, unsigned int coy)
{
m_pixelvalue=GetPixel(m_dcMem1, cox, coy);
return m_pixelvalue;
}
BOOL CThongThongThongDlg::GoWatermark(unsigned long ValueValue, int CoordinateX, int CoordinateY)
{
NewSettedPixelValue=m_dcMem1.SetPixel(CoordinateX, CoordinateY, ValueValue);
UpdateData(FALSE);
return TRUE;
}
please take note at those lines in [B]BOLD[/B] .. when i put in this lines..to loop... the function does go..(i mean..the results i got is nothing...not working).. but if i delete those lines(those loops)..the function will run properly.. i really need to loop..its very important..
this is a school project.. where i need to read the bits values inside the 24-bit BITMAPS and do some modification of its RGB LSB.. i really need help.
thanks a lot.
thong
twh81@tm.net.my
...
|
|
|
|
|
Is this a "deliberate" typo?
if(CoX {<br />
CoX+=1;<br />
}
Shouldn't it be
if(CoX)<br />
{<br />
Cox += 1;<br />
}<br />
else<br />
{<br />
CoY+=1;<br />
CoX=0;<br />
}
It is amazing what you can accomplish if you do not care who gets the credit. - Harry S Truman
|
|
|
|
|
His code is actually:
if(CoX < m_bmInfo1.bmWidth)
{
CoX+=1;
}
else
{
CoY+=1;
CoX=0;
}
|
|
|
|
|
Thanks, that is not what I see on IE6!
Perhaps he could give a link to the source code? I could not see anything obviously wrong. But it could have been screwed durin cut/paste.
It is amazing what you can accomplish if you do not care who gets the credit. - Harry S Truman
|
|
|
|
|
I don't see it either. Looks like IE6 swallowed the "<" as an HTML tag. He needs to wrap his sample code with <code></code> tags.
|
|
|
|
|
I can see two things that the for loop might affect.
1) the incrementing of PixelCount . This is used in the dereferencing of Data_0 and Data_1 . Are the arrays large enough?
2) the incrementing of CoX and CoY . Those are used by PixelValue() and GoWatermark() . Can those functions handle values greater than 0?
|
|
|
|
|
Hi all,
i've posted this question before and still no reply.....
when i create a new snap-in project (MMC) , the default menu in the menu bar is "Action, View, Favourties" i want to remove the "Favourites" menu item
i don't know how to do that. i know it is possible, i saw that sql server enterprize manager (which is a snap in object) removed it....so it is possible
can any1 help this time???
thanks in advanced
yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
error C2440: '=' : cannot convert from 'struct cell ** ' to 'struct cell *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
sortset.obj - 1 error(s), 0 warning(s)
The error appear to be in this line
temproot = (cmp_res < 0) ? &temproot->left : &temproot->right;
Anyone have a clues on how to fix this?
thank you very much ^_^
|
|
|
|
|
mmmm, smells like homework
Try removing the ampersands, assuming that temproot and the left and right nodes are of type "cell *"
For an explaination why, consult someone who can be bothered to explain pointers
--
Ian Darling
If I was any more loopy, I'd be infinite.
|
|
|
|
|
Hello, Can I add my aplication in Internet Explorer Rebar, How??
Visual C++ MFC
|
|
|
|
|
i create a font in the usual way :
first i set the properties (fontname, height, weight, angle, ...) in a LOGFONT struct,
then
myFont.CreateFontIndirect(&logfont);
then
pDC->SelectObject(&myFont);
then i call pDC->GetTextMetrics & pDC->GetTextExtent to to get some useful values
(total height, height of the ascent & descent parts), ... With these values i known exactly the boundaries of the text.
Problem : for a same height specified in the LOGFONT struct, the height values returned by GetTextMetrics vary with the angle of the text.
More precisely : if the angle is precisely 0 or 90 or 180 or 270°, the height is correct : if a draw a rectangle with the width & height computed from these values, it will perfectly fit around the text.
For any other values of the angle, the height is about 10 % too big.
|
|
|
|