|
I want to use of your code freely?
|
|
|
|
|
char str[8];
cin >> str;
When run, if inputed string size more than eight byte, result run time error.
So, how to limit cin >> size or only get eight byte when inputed more than eight?
thanks!
|
|
|
|
|
allocate memory dynamically based on the size of the string
You can use a loop (upto 8) along with getch()/getchar() to get the user input
Some things seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
cin statement doesn't provide you with limited input support. since it wait for RETRUN/ENTER key for updating the input character in buffer supplied to it.!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/xml>
|
|
|
|
|
std::cin.get(str, sizeof(str), '\n');
or
std::cin >> std::setw(sizeof(str)) >>str;
|
|
|
|
|
hanlei0000000009 wrote: When run, if inputed string size more than eight byte, result run time error.
Were you expecting a different result? Why not use a string object instead?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Hi Experts,
How can I import .rtf or .doc file content into TextBox.
|
|
|
|
|
Could anybody give reply?
|
|
|
|
|
For import doc file use rich edit control instead of edit control.
|
|
|
|
|
If you were using a rich edit control instead, you could just stream the data in.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Hi,
How can i get the path of the file opened, if i know that window handle.Is there any API for this.
Thanks
|
|
|
|
|
revanth1985 wrote: if i know that window handle
you can't find the name of file if you have window/FILE handle.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/xml>
|
|
|
|
|
If you are asking how to get the filename of an executable by knowing a window handle then this is how you do it. This code will tell you the PID of the executable even if you pass a child handle such as a button handle.
#pragma comment(lib, "psapi")
DWORD dwPID = -1;
BOOL CALLBACK EnumChildWindowsProc(HWND hWnd, LPARAM lParam)
{
if(hWnd == (HWND)lParam)
{
GetWindowThreadProcessId(hWnd,&dwPID);
}
return TRUE;
}
BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam)
{
if(hWnd == (HWND)lParam)
{
GetWindowThreadProcessId(hWnd,&dwPID);
}
else
{
EnumChildWindows(hWnd,EnumChildWindowsProc,lParam);
}
return TRUE;
}
BOOL FindWindowProcessModule(HWND Hwnd, TCHAR *szName,size_t iMaxLen)
{
EnumWindows(EnumWindowsProc,(LPARAM)Hwnd);
if(-1 != dwPID)
{
HMODULE hModule = NULL;
DWORD dwNeeded = NULL;
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,FALSE,dwPID);
if (NULL != hProcess)
{
if(EnumProcessModules(hProcess,&hModule,sizeof(hModule),&dwNeeded))
{
GetModuleFileNameEx(hProcess,hModule,szName,iMaxLen);
}
else
{
GetProcessImageFileName(hProcess,szName,iMaxLen);
}
CloseHandle(hProcess);
}
}
return NULL != szName[0];
}
Here is how you would use it:
TCHAR szName[MAX_PATH] = {0};
HWND Hwnd = (HWND)::FindWindow(_T("SciCalc"),_T("Calculator"));
if(FindWindowProcessModule(Hwnd,szName,MAX_PATH))
{
MessageBox(szName);
}
else
{
MessageBox(_T("Calculator is not running."));
}
Best Wishes,
-David Delaune
|
|
|
|
|
Hi,
Thanks for your reply.I don't want the path of the executable file,i want the working station of that file(for ex: D:\Work\New Text Document.txt).
|
|
|
|
|
You want the name of the process which has the file opened?
|
|
|
|
|
What i want is if a file is opened from D:\work\New Text Document.txt ,i want to get the path as stated before not the process name notepad.exe or excel.exe or some thing.can you help me out in this.
|
|
|
|
|
You can use function _getcwd(char* buffer,int maxlen) which will give you current directory. I hope this is you are looking for.Following simple code shows you how to use it.
char* buff,buffer[255];
buff = _getcwd(NULL,0);
cout<<buff<<endl;
|
|
|
|
|
SRKSHOME wrote: You can use function _getcwd(char* buffer,int maxlen) which will give you current directory.
How does that even come close to being a helpful answer?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
If you are asking how to find the filename/path from a FILE handle then perhaps the following code will help. Unfortunately it involves usage of some advanced undocumented functions. The following code is for Windows 2000 and above and completely unsupported.
typedef LONG NTSTATUS;
#define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0 && Status < 0x3FFFFFFF)
typedef struct _IO_STATUS_BLOCK {
union {
NTSTATUS Status;
PVOID Pointer;
};
ULONG_PTR Information;
} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
typedef struct _UNICODE_STRING
{
USHORT Length;
USHORT MaximumLength;
PWSTR Buffer;
} UNICODE_STRING, *PUNICODE_STRING;
typedef enum _FILE_INFORMATION_CLASS
{
FileNameInformation=9,
} FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;
typedef struct _FILE_NAME_INFORMATION
{
ULONG FileNameLength;
WCHAR FileName[MAX_PATH];
} FILE_NAME_INFORMATION, *PFILE_NAME_INFORMATION;
NTSTATUS (NTAPI *NtQueryInformationFile)(HANDLE,PIO_STATUS_BLOCK,PVOID,LONG,FILE_INFORMATION_CLASS);
CString GetFileNameFromHandle(HANDLE hFile)
{
wchar_t wszFilename[MAX_PATH];
IO_STATUS_BLOCK stb;
FILE_NAME_INFORMATION str;
*(FARPROC*)&NtQueryInformationFile = GetProcAddress(GetModuleHandle(_T("ntdll.dll")),"NtQueryInformationFile");
DWORD Status=NtQueryInformationFile(hFile,&stb,&str,MAX_PATH,FileNameInformation);
return NT_SUCCESS(Status)?CString(str.FileName, str.FileNameLength / sizeof(WCHAR)):NULL;
}
Sample MFC usage:
CFile f;
f.Open(_T("C:\\Test.txt"),CFile::modeRead,0);
HANDLE hFile = f.m_hFile;
MessageBox(GetFileNameFromHandle(hFile));
f.Close();
Best Wishes,
-David Delaune
|
|
|
|
|
#include <cstdlib>
#include <iostream>
//#include<conio>
//#include<math>
//#include<stdio>
#define NumberOfTasks 50 // easy change number of tasks
#define MaxClock 100 // easy change clock interval for tasks to run
#define MaxTaskTime 0.001 // easy change randomazing for tasking
#define NumerOfCPUs 5 // number of multiple pc's used
#define MaxQSize 10
using namespace std;
struct t
{
int id; int runprocess; int duration;
}task[NumberOfTasks];
struct c{
int idle;
int nextideltime;
}cpu[NumerOfCPUs];
struct queue{
// int Qcounter;
// int termcounter;
// int Qcounter==L;
// int empty
// { if (int L=0; Qcounter<maxqsize;l++)>
t task;
}q[MaxQSize];
int main(int argc, char *argv[])
{
int clock=0;
int qindex=0;
int i;
// cpus
for(int ik=0;ik<numerofcpus;ik++)>
{cpu[ik].idle=0;cpu[ik].nextideltime=0;}
// tasks
for(i=0;i<numberoftasks;i++)>
{
task[i].runprocess=int(MaxTaskTime*rand());
cout<<"task:"<< task[i].runprocess << "\n";
}
// system
while(clock<=MaxClock)
{
cout <<"clock:" << clock << endl;
for(int ij=0;ij<numberoftasks;ij++)>
{if(task[i].runprocess==clock)
{}
// if -- for enter the system
} // for -tasks
for(int ik=0;ik<numerofcpus;ik++)>
{if(cpu[ik].nextideltime==clock) cpu[ik].idle=0;
} // for make cpu idle
for(int ik=0;ik<numerofcpus;ik++)>
{if ( cpu[ik].idle==0 && qindex!=0)
{
}
} // for q - enter one task from q to cpu
clock++;
} //while
system("PAUSE");
return EXIT_SUCCESS;
}
here i am suppose to create a queuing and statistics box.. showing how many task get queue or terminated if queue is full... i just don't have any idea how to do that part..
help!!
|
|
|
|
|
The code you've shown is full of syntax errors. Fix those, and make use of the <pre> tags to make it more readable.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
ok leave the code ...i was able to make a working one in C#
just help me in how to make counter which can count how many get queued.. and to make a counter that would count any thing over the queue limit...which would be terminated
an example or reference would be nice
don't mind C++ answer since i just need the idea.. its simple but i can't just grasp that part
thanks for replying
|
|
|
|
|
thanks
i just got it... sooo simple........... )))))) )))
good luck to others, sorry very busy with last sem exams, n major project stuffs or would have tried to help around a little
|
|
|
|
|
Hi I am new VC++. Currently i am java application that will make use of COM(Component Object Model) to get Interface information. Basically I am using a IDispatch interface object to get a pointer to LTypeInfo. And I am using the function 'GetTypeInfo'. The problem is the function returns 'S_OK' but still pTypeInfo (pointer) is null. Can somebody help me out. In which scenario GetTypeInfo will return 'S_OK' but still the pointer will be null.
Following is the code snippet
===================================
ITypeInfo* pTypeInfo;
m_hRet = m_pDisp->GetTypeInfo(0,LOCALE_SYSTEM_DEFAULT,&pTypeInfo);
if(m_hRet!=S_OK || pTypeInfo==NULL)
{
#ifdef DISPDRIVER_DEBUG
_tprintf(_T("GetTypeInfo failed: %x\n"),m_hRet);
#endif
if(pTypeInfo==NULL && m_hRet==S_OK )
MessageBox(NULL, "Error : pTypeInfo is null", "1", MB_OK);
return false;
}
===================================
Please help me,since i am totally stuck at this point. Thanks In advance.
|
|
|
|
|
I want to convert doc/txt file to PDF using C++ win32(Don't want any third party Library) console app.
Final o/p exe should be used as follows.
ConvertDocToPdf.exe source.doc tar.pdf
Thanks & Regards,
|
|
|
|