|
Hi all,
I'm developing ATL dll which will be used in C#. But I have done many things so far now I have to use either file operation (say fprintf) or string operations ("sprintf").
I have tried to do it as in the usuall fashion(like in normal exe) but when I'm calling the methods containing "fprintf or sprintf" in C# project it'll start throwing following error.
........................................
Debug Assertion Failed!
"location\system32\inetsrv\w3wp.exe"
File:sprintf.c
Line:55
Expression: (str != NU.LL)
............................................
when I hit retry i'll get the following messege
The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))
...................................................
As per me its not the right way to use fprintf/sprintf in ATL dlls I guess.
You can test it by creating simple ATL dll project and placing file operation including fprintf/sprintf, and calling the method in C#.
plzzzzz guide me to come over it.
Thanks,
Arun
|
|
|
|
|
I'd say you're passing garbage to the functions, because there is no difference in calling them from an .exe or a .dll.
--
Coming Soon to an Illegal DVD
|
|
|
|
|
I don't think so because I experimented with the fresh ATL project, by adding only 3 lines of extra code of file operation consists of "fopen, fprintf and fclose". Here also I have found that "fprintf" is posing same problem.
Please you can easily check it by creating simple ATL dll with a method consists of these file operation lines. And we should use that method in C#. It 'll definately throw the same error.
Regards,
Arun
|
|
|
|
|
I am a beginner. I have read some tutorials and newbie books on C++ but am having trouble doing things beyond the basics.
I am trying to display the HWND when i use certain Win32 functions such as GetForegroundWindow() for debugging purposes. When i use Win32 MessageBox or OutputDebugString such as below...
1)
m_foreHwnd1 = GetForegroundWindow();
MessageBox(NULL, (LPCSTR)m_foreHwnd1, "INFO", MB_OK);
2)
OutputDebugString("ForeHwnd1: ");
OutputDebugString((LPCSTR)m_foreHwnd1);
OutputDebugString("\n");
... I get errors like the following:
First-chance exception at 0x77e26673 in SendFocusWin.exe: 0xC0000005: Access violation reading location 0x00090548.
Unhandled exception at 0x77e26673 in SendFocusWin.exe: 0xC0000005: Access violation reading location 0x00090548.
I am not getting anywhere and am starting to get fustrated. What are the code steps i need to take to get the HWND value safely AND put it into a string variable that i can use elswhere in my code? What would be the ANSI solution?
|
|
|
|
|
why not you try CString instead?
<br />
CString csHWND;<br />
csHWND.Format("%l",m_foreHwnd1);<br />
AfxMessageBox(csHWND);<br />
If you dont use MFC, then
<br />
ltoa(m_foreHwnd1,szText,10);<br />
MessageBox(..szText..);<br />
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
|
|
|
|
|
I am restricting my learning to ANSI for now. I canot believe how hard it is to convert a number into a string in C++. ltoa will only convert a long into a string, not HWND. I have searched on the internet and did not find a single code snippet to convert HWND into a string. Certainly programmers print out HWNDs in order to debug their code!? How does one convert HWND into string un ANSI C++?
|
|
|
|
|
You're not supposed to be able to convert a HWND to a string.
Of course, if you treat it as a pointer, you'll get away with it.
CString str; str.Format(_T("%p"), hWnd);
But why you'd want that string, is beyond me. Maybe you want the window's caption/title instead? ::GetWindowText()...
--
Not Y3K Compliant
|
|
|
|
|
I found the answer. You folks have really played the tempting devil with your MFC code, but i am going to restrict my learning to ANSI C++/STL. I plan to develop on Linux/Mac too.
The following code works.
char buffer [100];
sprintf(buffer, "%I64d \n", (unsigned __int64) hwnd);
OutputDebugString(buffer);
The reason i want the HWND in a string is so i can dump debug info to troubleshoot a problem.
It seems that the hardest part of C++ is finding the information! By luck i found the answer on the internet. I had no clue that sprintf was to be used for this. I come from VB6/C# background and so these non-orthodox language commands throw me off. Once i learn the C++ quirks things will become straight forward.
|
|
|
|
|
redfish34 wrote: You folks have really played the tempting devil with your MFC code
Huh? The MFC's CString uses the same formatting specifiers as the printf-functions in the C library.
redfish34 wrote: char buffer [100];
sprintf(buffer, "%I64d \n", (unsigned __int64) hwnd);
OutputDebugString(buffer);
Why not use %p?? (Which incidently is standard C, and thus standard C++, while %I64d isn't).
redfish34 wrote: The reason i want the HWND in a string is so i can dump debug info to troubleshoot a problem.
For your own development purposes, I presume? The handle value itself tells you nothing once the window has been destroyed. Nothing, nada, zilch.
--
Larva-Tested, Pupa-Approved
|
|
|
|
|
RedFish wrote: "%I64d \n", (unsigned __int64) hwnd);
looks really weired.
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
-- modified at 10:18 Wednesday 5th July, 2006
|
|
|
|
|
Try this
char buf[16];
sprintf(buf, "0x%08x", hwnd);
OutputDebugString(buf);
You wont need 64 bit integers for your HWNDs.
-- modified at 18:59 Wednesday 5th July, 2006
|
|
|
|
|
Hi redfish, I'm sorry I missed to cast it (if you use ltoa). if you use CString the matter is much more simple.
Try this simple one:
<br />
CString cs;<br />
cs.Format("%x",this->m_hWnd);<br />
AfxMessageBox(cs);<br />
--------------OR---------------------------------<br />
char ch[10];<br />
ltoa((long)this->m_hWnd,ch,16);<br />
AfxMessageBox(ch);<br />
This will give you the exact format that you will find in the spy++.
redfish34 wrote: I canot believe how hard it is to convert a number into a string in C++.
but have a look at the 3rd parameter, it gives you the flexibility to convert to base 2(bin), 16(hex), 10(deci) etc.. Dont you find it useful?
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
|
|
|
|
|
redfish34 wrote: ltoa will only convert a long into a string, not HWND.
We have similar handle in our SDK which is not a struct, I typed it having that in mind. sorry
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
|
|
|
|
|
|
I have implemented a class that uses a shared reference count content as below:
class SharedContent<br />
{<br />
public:<br />
SharedContent(unsigned short size) : _size(size), _pCotent(new ContentType[_size]), _count(1) { }<br />
<br />
unsigned short getSize() const { return _size; }<br />
<br />
ContentType* getContent() const { return _pContent; }<br />
<br />
void decCount() const {<br />
_count--;<br />
if (_count == 0) {<br />
delete [] _pContent;<br />
delete this;<br />
}<br />
}<br />
<br />
void incCount() const {<br />
_count++;<br />
}<br />
<br />
private:<br />
unsigned short _size;<br />
ContentType* _pContent;<br />
mutable int _count; };<br />
<br />
class ReferenceObject {<br />
public:<br />
ReferenceObject() : _content(NULL) { }<br />
<br />
ReferenceObject(unsigned short size) : _content(new SharedContent(size)) { }<br />
<br />
ReferenceObject(const ReferenceObject& rhs) : _content(NULL) { *this = rhs; }<br />
<br />
~ReferenceObject() {<br />
if (_content != NULL) _content->decCount();<br />
}<br />
<br />
ReferenceObject& operator=(const ReferenceObject& rhs) {<br />
if (_content != NULL) _content->decCount();<br />
_content = rhs._content;<br />
if (_content != NULL) _content->incCount();<br />
}<br />
<br />
unsigned short getLength() const {<br />
return _content == NULL ? 0 : _content->getSize();<br />
}<br />
<br />
ContentType* getContent() const {<br />
return _content == NULL ? NULL : _content->getContent();<br />
}<br />
<br />
ReferenceObject clone() const {<br />
return clone(0, getSize());<br />
}<br />
<br />
ReferenceObject clone(int offset, int size) const {<br />
ByteArray result(length);<br />
memcpy(result.getContent(), getContent() + offset, size);<br />
return result;<br />
}<br />
<br />
<br />
private:<br />
SharedContent* _content;<br />
};
When I enqueued the object into a std::deque and dequeued and erased it afterwards, I found that the reference count does not function well such that the counter drops to 0 and raises again. This destroys the SharedContent object and accesses the destroyed content, which causes failure to the program. The code is similar to the following:
void addElement(unsigned short size, std::deque<ReferenceObject>& objectQueue) {<br />
ReferenceObject obj(size);<br />
objectQueue.push_back(obj);<br />
}<br />
<br />
int main {<br />
std::deque<ReferenceObject> objectQueue;<br />
for (int i = 0; i < 10; ++i) {<br />
addElement(i, objectQueue);<br />
}<br />
std::deque<ReferenceObject>::iterator itr = objectQueue.begin();<br />
while (itr != objectQueue.begin() + 3) {<br />
ReferenceObject obj = *itr;<br />
++itr;<br />
}<br />
objectQueue.erase(objectQueue.begin(), itr);<br />
return 0;<br />
}
I use valgrind to check the memory problems, I found that problem occurs at erase() function that the reference count is dropped to 0 when accessing the obj in queue B. Could anyone show me what's wrong with the ReferenceObject? Thank you.
-- modified at 4:20 Monday 3rd July, 2006
|
|
|
|
|
I suspect it might be this method, in the case when rhs._content == this->_content :
ReferenceObject& operator=(const ReferenceObject& rhs) {
if (_content != NULL) _content->decCount();
_content = rhs._content;
if (_content != NULL) _content->incCount();
}
Try this instead - it copes when rhs._content == _content :
ReferenceObject& operator=(const ReferenceObject& rhs) {
if (_content != rhs._content)
{
if (_content != NULL) _content->decCount();
_content = rhs._content;
if (_content != NULL) _content->incCount();
}
}
|
|
|
|
|
|
Hey!
I develope Windows form with infragistic controls. When I open the Form, whole form is not appearing at onece. Before become visible windows standart controls and there where infragistics controls should be, those areas are transparent and background application is visible. Only after the moment infragistic controls appear.
Does any one know why it is acting like this?
Is there any workaround?
Thankyou in advance.
Del
-- modified at 5:52 Saturday 1st July, 2006
|
|
|
|
|
class tagtree
{
...
public:
std::map<CString,tagtree*> mapControllee;
};
** working code **
tagtree *tt;
tagtree *ttController;
tt = AddNode(...);
ttController = tt;
tt = AddNode(...);
ttController->mapControllee[strName] = tt; <- assert and crash at compare down to _tcmp with pointer lpsz = 0xcdcdcdcd("")
anyone help? i use map quite regularly..
from,
-= aLbert =-
|
|
|
|
|
stl better
a["a"] = p
result?
Kuphryn
|
|
|
|
|
bug in xtree
from,
-= aLbert =-
|
|
|
|
|
You haven't posted enough code for the problem to be visible. What does AddNode do? Clearly we need this as it determines the value of tt and ttController . One thing I'll say - The problem is almost certainly with AddNode .
Steve
|
|
|
|
|
the AddNode is nothing more than just "new tagtree with tagtree's attributes".
during the config process between tagtree could be linked by using tagtree's map.
my post there is to get attention from ppl who met this problem b4. if u never met it,
i have to be frank it is quite unlucky day then u will see it. it is a bug in stl library.
i fix it by patching my stl xtree file used by map. the bug never go away after
service pack 5 for vc6.
simply google dinkumware. they are the one who write stl lib in vc6.0
from,
-= aLbert =-
|
|
|
|
|
Hello CPians,
I am back with another question.
Ok, so I am gonna get straight to the point. I have custom Window which was derived from CFrameWindowImpl . Now the class which handles this Window has a Constructor and a Destructor . All the Window logic is written in this class. When I create a window, I do this.
CFrameWindow myWindow ;<br />
myWindow.Create() ;
which creates the Window. Now, when the application ends, I know for sure that the destructor of CFrameWindow is called. What if I had done this?
CFrameWindow *myWindow ;<br />
myWindow->Create() ;
then I would have to call delete myWindow ; to call the destructor. This is fine with an application. But supposing the window Window1 is created by another window, Window2 . When Window1 closes, it informs Window2 that it is being destroyed. This notification is sent during WM_NCDESTROY .
My question when in Window2 do I make the call delete Window2 ? I would have to free the memory.
Any help?
---
Hakuna-Matada
It means no worries for the rest of your days...
It's our problem free, Philosophy
|
|
|
|
|
Typically you would override OnFinalMessage() to delete this. If you are still using VC6 (ATL3) then you might encounter some problems with this solution though (http://vcfaq.mvps.org/com/10.htm[^]).
|
|
|
|