|
Since the buffer the O.P. allocated is a char buffer, they need to be using it with the ANSI version of the function. If their app is a UNICODE build, GetWindowText(...) will resolve to GetWindowTextW(...) , and will not accept the char buffer.
Identifiers like GetWindowText that are #defined to different functions (the A or W versions) depending on the build type should only be expected to work correctly under different build types when using TCHAR as the character type.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
It is likely ASSERTing because the you are passing the return from strlen(...) as the length of the buffer. These are two different things.
You should be calling the function like: m_Pswd.GetWindowTextA(sCurPswd,512) .
Peace!
--- Modified at 10:34 Tuesday 14th February, 2006
Actually, the second parameter is the max number of characters to copy into the buffer. This is important, because it does not mean the size of the buffer. That is why using sizeof(...) as was also suggested would be incorrect in a UNICODE build.
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
-- modified at 10:34 Tuesday 14th February, 2006
Actually, the second parameter is the max number of characters to copy into the buffer. This is important, because it does not mean the size of the buffer. That is why using sizeof(...) as was also suggested would be incorrect in a UNICODE build.
|
|
|
|
|
Amarelia wrote: m_Pswd.GetWindowTextA(sCurPswd,strlen(sCurPswd)); //Here it give assertion
Use sizeof(sCurPswd)*sizeof(TCHAR) instead of strlen(sCurPswd) .
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
DavidCrow wrote: Use sizeof()*sizeof(TCHAR) instead of strlen().
Sorry you bug you Sir, Couldn't we use lstrlen for same?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
ThatsAlok wrote: Couldn't we use lstrlen for same?
Sure you can use it, but it'll still return 0 just like strlen() .
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
hi All,
I want to integrate crystal reports into my MFC app. I have already done this using an Access db as a data source. But what I really want to do is to use an XML file as a data source. How do i do this?
I tried to modify the connection string:
// Connection String
_bstr_t bstrAccessConnect ( L"DRIVER={Microsoft Access Driver (*.mdb)};"
L"DBQ=Database.MDB;"
L"DefaultDir=;"
L"UID=admin;PWD=;"
L"Mode=Read;");
but it didnt work. I have configured the ODBC dsn according to the CR XML v3.6 driver. It is correct because I can access the XML file as an ODBC dsn from the Crystal reports manually...So how do i do this in code???
PS: I hav Crystal Reports 8.5
|
|
|
|
|
Hi,
I have a service installed on Windows 2003 Server OS. I would like to disable the "restart service" button and menu option in the services applet.
Some services like "Event Log", RPC, etc have them disabled.
Thanks,
Mel
|
|
|
|
|
Hi Friends,
Please check the following code.
PROCESS_INFORMATION piProcInfo;
STARTUPINFO siStartInfo;
ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION) );
ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) );
siStartInfo.cb = sizeof(STARTUPINFO);
bool bRet=CreateProcess("C:\\apps\\Microsoft Office\\OFFICE11\\WINWORD.EXE",
NULL,// command line
NULL, // process security attributes
NULL, // primary thread security attributes
TRUE, // handles are inherited
0, // creation flags
NULL, // use parent's environment
NULL, // use parent's current directory
&siStartInfo, // STARTUPINFO pointer
&piProcInfo); // receives PROCESS_INFORMATION
DWORD dw=GetLastError();
if(NULL != bRet)
{
if(WAIT_OBJECT_0==WaitForSingleObject(piProcInfo.hProcess,INFINITE))
{
MessageBox(NULL,"Finished","Error",MB_OK);
}
}
here...WaitforSingleObject does not wait for WinWord app to finish...it just quits....Any soln/Reason?
Vikram S
|
|
|
|
|
vikrams wrote: TRUE, // handles are inherited
make it FALSE
Regards
Anil
|
|
|
|
|
Still it's not working...!
|
|
|
|
|
Just a thought...
bool bRet;
"if(NULL != bRet)"
Is it OK to compare bool with NULL?
|
|
|
|
|
Good point to notice.
I didn't noticed that.
Regards
Anil
|
|
|
|
|
After I wrote my response, I tried it out.
It works the way you wrote it. Even tough sizeof(bool) == 1 and sizeof(NULL) == 4.
So your test isn't skipped (as I suspected).
|
|
|
|
|
|
vikrams wrote: bool bRet=CreateProcess("C:\\apps\\Microsoft Office\\OFFICE11\\WINWORD.EXE",
...
if(NULL != bRet)
Why are you checking for NULL when CreateProcess() returns a BOOL value? Change bool to BOOL and compare against TRUE /FALSE .
vikrams wrote: ...it just quits
What quits?
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
WaitforSingleObject does not wait for WinWord app to finish...it just quits
|
|
|
|
|
I'm not sure what the problem is. I tried your code, along with my two changes, and it works fine.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
Hi Guys,
The code works Fine with admin privileges otherwise it fails...
Vikram S
|
|
|
|
|
strangly This admin previleges are needed for Winword.exe only.Excel,notepad and other applications works fine with a normal user account.
|
|
|
|
|
I am trying to program something that I assume is possible. Essentially I want to load a DLL library function in one program (say, program A), and using getprocaddress, I want to call this function from another program, B, purely by using the function's pointer/address.
My question is basically; how do I define and use the DLL function in program B? (only knowing its address in memory.)
|
|
|
|
|
You can't,
The dll's function is loaded into the memory space of program A and only usable from whitin this memory space.
This use to be possible on older OS but when a program crashes it could take other programs to.
Therefore each program has it own memory space where the dll is loaded in for each program.
I think however it is still possible to place some data (contained in the dll) in a shared memory block so that each dll can use this data (dangerous) but I don't think it is possible to do the same with funtion blocks.
codito ergo sum
|
|
|
|
|
if u know the function proto, first typedef it and then create an object of that type. for example if we want to call the
BOOL ShowWindow(HWND hWnd, int nCmdShow);
of User32.dll,
1. typedef its proto
typedef BOOL (WINAPI * myShowWindow)(HWND hWnd,int nCmdShow);
2.Create an object
myShowWindow fun_myShowWindow;
3. Assign the pointer obtained from GetProcAddress() to fun_myShowWindow
$. now u can call the function fun_myShowWindow as usual
eg :- fun_myShowWindow( m_hwnd, SW_SHOW);
nav
|
|
|
|
|
|
Naveen raj mohan wrote: 3. Assign the pointer obtained from GetProcAddress() to fun_myShowWindow
Can I explicitly define an address? Like:
fun_myShowWindow = 0x100021e0; (or something)?
Otherwise I am afraid BadKarma may be right
|
|
|
|
|
pjama wrote: Can I explicitly define an address? Like fun_myShowWindow = 0x100021e0
certainly not...
well, yes, the code would compile, but this will never work, as you cannot know at what address your function will be loaded...
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]
|
|
|
|