|
I have developed a mutithreaded FTP application for uploading more than one files simultaneously. I have used MFC's CFTPConnection class for establishing connection and for transferring files. For every file, i have to transfer i connect to the FTP server using GetFTPConnection and then transfer file using PutFile. But after uploading few files CPU usage shoots up to 100%. Can any body tell me the reason for this.Sometimes it does not last long but sometimes it lasts long and the application hangs. Currenltly 5-6 threads are active at a time and other that this there is one more thread running in my application to chck the FTP connection is axctive or not.
|
|
|
|
|
The most likely cause for 100% CPU is that you have a runaway thread that is not correctly waiting, is stuck in an infinite loop, infinite recursion, or something like that which causes it to use all the CPU. Place a few TRACE statements in the threads and one of them will go mad with output - thats your culprit!
|
|
|
|
|
I saw the sample program of how to print out in a formview.
The code is following. Right now I want to print out the image
to fit into paper( if A3 larger image than A4). How to achieve this?
CPoint oldPoint = GetScrollPosition( );
CPoint pt( 0, 0 );//scroll to up
this->ScrollToPosition( pt );
CClientDC dc(this);
CRect rect;
m_dib.Attach( GDIUtil::GrabDIB( &dc, rect ) );
ScrollToPosition( oldPoint );
|
|
|
|
|
i use following code
#include <Iads.h>
#include <Adshlp.h>
#pragma comment(lib, "ActiveDS.Lib")
#include <COMDEF.H>
bool CheckUserADSI(const char* parUserName, const char* parCode)
{
IADsOpenDSObject* pObject = NULL;
IDispatch* pDisp = NULL;
bool RetValue = false;
HRESULT hr = S_OK;
_bstr_t UserName (parUserName);
_bstr_t Code (parCode);
hr = ADsGetObject(L"LDAP:", IID_IADsUser, (void**) &pObject);
if (SUCCEEDED(hr))
{
hr = pObject->OpenDSObject(L"LDAP://net.blum",UserName, Code, ADS_SECURE_AUTHENTICATION, &pDisp);
pObject->Release();
if (SUCCEEDED(hr))
{
RetValue = true;
}
}
pDisp = NULL;
pObject = NULL;
return RetValue;
}
when i compile the code, the compiler says:
WinLogon.obj : error LNK2001: unresolved external symbol _IID_IADsUser
Any ideas how to solve this problem ?
I've checked the platform SDK samples.. all are using this IID.. but i haven't seen a single include or lib file they were linking..
"I'm from the South Bronx, and I don't care what you say: those cows look dangerous." U.S. Secretary of State Colin Powell at George Bush's ranch in Texas
|
|
|
|
|
#include <activeds.h>
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
guess you forgot to use the <> - Tags.. so your include got stripped..
"I'm from the South Bronx, and I don't care what you say: those cows look dangerous." U.S. Secretary of State Colin Powell at George Bush's ranch in Texas
|
|
|
|
|
#include <activeds.h> is there, you just have to look real close!
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Hi,
use "__uuidof ( expression )", where "expression" is interface name ie "IADsUser".
The chosen One
|
|
|
|
|
How to print from the Dialog Box?
Hello!
I have come across some problem hope some one could help me out..
I have got a MFC based dialog box on which i have various controls liek edit boxes, static labels and pushbuttons. For one of the push button say whose caption is "PRINT" i have given the functionality of Printing the same dialog box. I need the dialog box to be printed as is when i click the print button. So what the code should contain and my approach is as follows...
void PrintTest:nPrint()
{
CDC dc;
CPrintDialog dlg(FALSE);
//dlg.GetDefaults();
if(dlg.DoModal() == IDOK)
dc.Attach(dlg.GetPrinterDC());
DOCINFO di;
::ZeroMemory(&di, sizeof(DOCINFO));
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = _T ("print this dialog");
dc.StartDoc(&di);
return;
}
Is my approach correct. I have a doubt, how do i get the dialog handle or the device context i mean the dialog's context so that i can pass the same to the printfunction.
Venky
|
|
|
|
|
See if these two articles give you any pointers:
http://flounder.com/printbitmap.htm
http://flounder.com/screencapture.htm
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
How to print from the Dialog Box?
Hello!
I have come across some problem hope some one could help me out..
I have got a MFC based dialog box on which i have various controls liek edit boxes, static labels and pushbuttons. For one of the push button say whose caption is "PRINT" i have given the functionality of Printing the same dialog box. I need the dialog box to be printed as is when i click the print button. So what the code should contain and my approach is as follows...
void PrintTest:nPrint()
{
CDC dc;
CPrintDialog dlg(FALSE);
//dlg.GetDefaults();
if(dlg.DoModal() == IDOK)
dc.Attach(dlg.GetPrinterDC());
DOCINFO di;
::ZeroMemory(&di, sizeof(DOCINFO));
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = _T ("print this dialog");
dc.StartDoc(&di);
return;
}
Is my approach correct. I have a doubt, how do i get the dialog handle or the device context i mean the dialog's context so that i can pass the same to the printfunction.
Venky
|
|
|
|
|
http://www.codeproject.com/dialog/msgboxdemo.asp?df=100&forumid=1419&exp=0&select=632516#xx632516xx
According to the above, I created a MFC-AppWizard exe project(Dialog-based) and added the files "timedmsgbox.cpp" and "timedmsgbox.h" to it,then changed the afximpl.h path as: #include "C:\\Program Files\\Microsoft Visual Studio\\VC98\\MFC\\SRC\\afximpl.h"
My computer's OS is WindowsXP sp2
Compiling tool is VC6
The compiling result is like the below
How can I solve these problems?
Compiling...
timedmsgbox.cpp
d:\projects\timedmsgboxtest\timedmsgbox.h(44) : error C2146: syntax error : missing ';' before identifier 'm_sectMap'
d:\projects\timedmsgboxtest\timedmsgbox.h(44) : error C2501: 'm_sectMap' : missing storage-class or type specifiers
D:\projects\TimedMsgBoxTest\timedmsgbox.cpp(28) : error C2039: 'm_sectMap' : is not a member of 'CDlgTimedMessageBox'
d:\projects\timedmsgboxtest\timedmsgbox.h(23) : see declaration of 'CDlgTimedMessageBox'
D:\projects\TimedMsgBoxTest\timedmsgbox.cpp(28) : error C2146: syntax error : missing ';' before identifier 'm_sectMap'
D:\projects\TimedMsgBoxTest\timedmsgbox.cpp(28) : error C2501: 'CCriticalSection' : missing storage-class or type specifiers
D:\projects\TimedMsgBoxTest\timedmsgbox.cpp(28) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
TimedMsgBoxTest.exe - 6 error(s), 0 warning(s)
|
|
|
|
|
Add <afxmt.h> to your StdAfx.h header file, then Rebuild All.
|
|
|
|
|
It work well now
Thank you!
|
|
|
|
|
Hi,
I hope you have solved the current problem as replied by Mike.
When u get error as above, "error C2501: 'CCriticalSection' : missing storage-class or type specifiers", immidiately search "CCriticalSection" on MSDN.
There you will get header file u need to include.
Compiler follows set of instructions. If u forget including header files, it will throw error like above. Error numbers reported by VC compilers are described in detail on MSDN.
If u get compiler concepts clear, u will never face problem in solving such errors.
The chosen One
|
|
|
|
|
Great!
What a good lesson!
I don't know what to do about these errors before.
Thanks a lot for both of you!
|
|
|
|
|
I'm trying to extract Thumbnail images of files.
I've used IExtractImage and it works great, except that when it gets to internet shortcuts, it hangs for a long time (10-20 seconds) and always fails.
<br />
TCHAR path[MAX_PATH];<br />
DWORD priority = 0;
DWORD flags = IEIFLAG_ASPECT;
HBITMAP handle = NULL;<br />
CSize requestedSize(75,56);<br />
<br />
if (S_OK == imageExt->GetLocation(path, MAX_PATH, &priority, &requestedSize, 32, &flags))<br />
{<br />
hr = imageExt->Extract(&handle);<br />
<br />
if (S_OK == hr)<br />
{<br />
item->thumbnail = new CMyBitmapFromHandle(handle);<br />
}<br />
}<br />
<br />
imageExt->Release();<br />
I've tried various flags like with or without IEIFLAG_OFFLINE but nothing makes it work.
Does anybody spot the problem ?
Thanks
|
|
|
|
|
Originally, I had a 'struct' in a file along with other 'structs'. Then I added a new class to the program and because this particular 'struct' seemed so well suited with this new class, I moved the 'struct' into the same file with the new class.
Now, even though the file in which the new class is located, has the '#ifndef (etc.)' macro/preprocessor statement, the program will not compile and link due to a LNK2005 error.
The new class is being '#included' in several different class files, and the compiler is not complaining about the new class being multiply defined. Why is the 'struct' the problem?
Thanks for any insight.
William
Fortes in fide et opere!
|
|
|
|
|
Visual C++ sometimes fails to compute dependencies correctly, so you could have a stray definition in an object file from before the move. Try a Rebuild All.
Otherwise, I don't think it's possible to give guidance without seeing the header (so long as it isn't too long - trim out any private implementation and check that the error still occurs) and the exact error message.
|
|
|
|
|
Thanks for replying. (Of the others that have been posted, your's make the most sense.)
Here's the code for the struct file:
#idndef STRUCT_H
#define STRUCT_H
struct FirstStruct
{ etc. };
struct SecondStruct
{ etc. };
...
struct ThisStruct
{ etc. };
#endif // STRUCT_H Here's the file containing the new class:
#idndef HDR_H
#define HDR_H
struct ThisStruct
{ etc. };
class NewClass
{ ctor; dtor; etc. };
#endif // HDR_H Clearly it's a Visual C++ misdoing, because there's no C++ syntactical error involved, and if I were to put the 'struct' back to where it was originally located, the program compiles and links well. Then if I were to replace it back with the new class again, the linker acts up and produces the error. Next, if I were to comment out the 'struct' (where it exists in the file with the new class) it compiles and links well. It's ONLY when it appears openly (but separately and apart) from the new class, that the LNK2005 error message reappears.
Of the many situations I tried in getting it resolved, more than half of them involved doing a total "Rebuild all", but the problem still persist.
Yes, I've also deleted the ".ncb" file and a few others too, followed by a "Rebuild all". No difference.
William
Fortes in fide et opere!
|
|
|
|
|
Could the compiler be picking up an old version of your header files?
Visual C++ 7.x supports the /showIncludes switch, which will cause the preprocessor to output where it found the include files. In the environment, this is under Project Properties > Configuration Properties > C/C++ > Advanced > Show Includes.
Visual C++ 6.0 doesn't support this, so you'll have to get it to generate preprocessed output and look through it for the struct definition. You must add the /P /C switches manually (/C keeps comment lines, which will be helpful in locating the problem).
I'm still surprised this is causing a linker, rather than a compiler, error - are you sure that the linker isn't complaining about multiple definitions of a variable or of a function?
|
|
|
|
|
Thanks again for replying.
Your sharp insight into the circumstances I have been describing, provided the clue (more like the answer) to what was needed in order to solve the problem.
When you asked if I was sure that the linker wasn't complaining about the multiple definition of a variable or function, I double check and instantly saw what was the problem. I had:
struct ThisStruct
{ etc.} *pThisStruct; As soon as I removed "*pThisStruct", compiled and linked again, the problem went away.
The reason why such a problem did not exist before, was because the file containing all those structures were being accessed by one (and only one) other file, but to the new file where I relocated that structure, that file is being accessed by three other ".cpp" files, and that's where the multiple redefinitions were occurring.
Thanks again for this big help. I appreciate it.
William
Fortes in fide et opere!
|
|
|
|
|
Hey Mike,
Come to think of it, even though I got a clean compile and link by removing the pointer variable to the 'struct', it shouldn't have mattered because the "#ifndef HDR_H" (etc.) preprocessor statements affiliated with this header file, GAURANTEES that the file would only be "#included" just ONCE!!!!
Therefore, no matter how many times I wish to "#include" that header file elsewhere, the compiler should see it just ONCE!!! (Am I right, or wrong???)
Therefore that pointer variable should NOT have caused any problem. Certainly not the kind the linker was reporting.
William
Fortes in fide et opere!
|
|
|
|
|
The problem is that the same header was included in more than one source file (a preprocessed source file, i.e. including the text of all headers, is referred to as a translation unit in C++ compilation terminology).
The compiler can only 'see' the translation unit it's working on at any one time - it can't see the others.
If you have a.cpp and b.cpp , both of which include hdr.h , and hdr.h includes the definition of a variable, both a.obj and b.obj , generated by the compiler, will contain the definition.
When the linker is instructed to link the objects together, it discovers it has multiple definitions of the same symbol, and aborts with the error.
You should never (or very rarely) define a variable in a header file. If you need to refer to a common variable, declare it extern .
(If you really need to: look up __declspec(selectany) ).
|
|
|
|
|
While you do make a lot of sense about what you're saying, I always thought variables, functions, classes and structures defined in the same file (be it a header or an implementation file) reside in the same file scope, and for variables and functions defined OUTSIDE a structure or a class, were considered to be global (of sort).
It might sound like I am talking apples and oranges here, but the idea of scope delimited by the preprocessor statements "ifndef HDR (etc.)" guarantees that those symbols (i.e. variables, functions, etc.) would only be processed (or seen by the compiler) just ONCE!!
"extern" simply says, "Take my word for it, this variable (etc.) you see here, has been defined elsewhere." Its purpose is not just to prevent redefinition (which even so, is questionable because symbols appearing in different files are doing so in a different namespace and would not necessarily be duplicates), but also to prevent problems relative to timing (i.e. at what point does a variable (etc.) becomes known to the system since the compiler does not guarantee a specific order of introduction).
I am trying to think back to all those times when I have defined variables (etc.) OUTSIDE a class, believing that they were symbols simply being defined at file scope (a sort of global version in a way) but that I was safe because the system was only going to see them ONCE if I were to surround EVERYTHING in the file with the "#ifndef (etc.)" preprocessor statements!!
William
Fortes in fide et opere!
|
|
|
|
|