|
There are two ways to do that:
1) If you have already opened the file use this:
CFileStatus status;
ReadFile.GetStatus(status);
LONG size = status.m_size;
2) more general way is this:
CFileStatus status;
CFile::GetStatus(_T("myfile.dat"),status);
LONG size = status.m_size;
|
|
|
|
|
I'm doing a get text on a drop down box into a CString. I then do a strcpy to a char array so that I can pass this info off to a LPSTR in a cobol DLL.
When I do a GetWindowText on this combo box and then do my strcpy I get an Assertion failed.
So how can I get this info and convert it to a LPSTR with out doing a strcpy. And How do I delete the char array when I'm finished with it?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
The assertion generally means that the code has detected that you are calling it incorrectly. So:
1) Post the code that is causing the problem.
2) Where is the assertion occurring? Is it in the GetWindowText()? In the strcpy()? Or somewhere in your code?
Dave
http://www.cloudsofheaven.org
|
|
|
|
|
Okay. Here is some of my code.
CString CSRAgcy;<br />
char shold[4];<br />
<br />
m_CBAgencyList.GetWindowText(CSRAgcy);<br />
strcpy(shold, CSRAgcy);
It errors out when I do the strcpy. If I comment out that line my program works fine.
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
What's probably happening is that your string is longer than 3 characters, and so the assertion is warning you that you are overwriting memory that you shouldn't.
You need to allocate enough memory to hold the entire string:
CString sTmp;
m_CBAgencyList.GetWindowText( sTmp );
char* pszAgency = new char[sTmp.GetLength()+1];
strcpy( pszAgency, sTmp );
// Do something with pszAgency
delete[] pszAgency;
Dave
http://www.cloudsofheaven.org
|
|
|
|
|
Thanks dave that did it. Can you explain in english what the line:
char* pszAgency = new char[sTmp.GetLength()+1];
does? Is it redefining a char array?
Thanks
Tom
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
The new operator allocates a block of memory, which is an array of chars, of length sTemp.GetLength()+1. The +1 is needed because in C/C++, strings are null-terminated, and the length of a string does not include the null-terminator.
char* pszAgency defines a pointer to a character, which in this case is the start of the block of memory we have just allocated.
Dave
http://www.cloudsofheaven.org
|
|
|
|
|
Again thanks for the help. That explained it clearly.
Tom
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
wouldn't be a little more efficient to just send the CB_GETTEXT message, passing the LPSTR to be filled in directly, rather than creating a CString, having the framework do what I just said, and converting it to an LPSTR? Also, I think that the other message would be CB_GETTEXTLEN?
onwards and upwards...
|
|
|
|
|
It would be more efficient, but probably not worth the effort, here as it is to be used in a cobol DLL. Since the text is to be retrieved from a combo box, it is unlikely to be very long either, so the little execution time saved is probably not very relevant here.
Dave
http://www.cloudsofheaven.org
|
|
|
|
|
While using simple MAPI in VC++ , how should I be specifying the Mail server addresses ?
|
|
|
|
|
Either by host name or IP address. If you use host name and it doesn't work, it could indicate a DNS problem.
|
|
|
|
|
I have script host embeded inside my MFC & ATL app.
It mostly reads/executes JScript code sending results back to MFC View to be displayed.
Program runs very fast when started from local drive, also I can place all scripts on shared netware volume and it will still take less then 1sec to display interface.
Trouble comes when executable is placed on netware volume. It takes 25sec to display first screen vs << 1sec local. After that everything runs fast again.
Profile lists
CWinThread::PumpMessage 27.9 seconds
AfxWinMain 31.8 seconds
IsLink 4.5 seconds
CMDIFrame::DefWindowProcA 3.5second
Not entirely unexpected as looks like system is waiting....
Numega TrueTime even more dramatic:
Application time: 0.29%
System Time : 99.71%
System Time: WaitForMultipleObjectsEx 99%
This function has been called by LoadRegTypeLib 90%
and GetFileAttribEx - 5%....
Those function called 100% by SetScriptState(SCRIPTSTATE_CONNECTED);
Have anybody seen such behaviour????
Any1 aware of any issues btw Netware and MFC & ATL?
P.S. I tried to SetCurrentDirectory to temp and it had no imact...
Compress executable with UPX... UPX unpacks file inside env "C:\TEMP" still darn 25seconds plus to start....
Any suggestions....
Thanks
Brian
|
|
|
|
|
I have a Winhelp file that calls a Microsoft DLL named HLP95EN.DLL
RR("HLP95EN.DLL","MsoCF","I=SII")
Here's what I know about this:
1. RR() is used to register a routine, which can then be used as a macro by Winhelp
2. the routine's name is "MsoCF"
3. the "I=SII" lists the routine's parameter types: LPSTR, int, int
Here's what I don't know:
1. what does this routine do?
2. in general, is there a way to get the contents of a Microsoft routine?
3. what does the "I= mean?
4. I understand that LPSTR specifies a pointer to a string, but since a Winhelp file is not a C program, I can't see how to assign a pointer to a string.
Could I send an actual string, eg: MsoCF("banana",1,2)?
I appreciate your help,
Al
|
|
|
|
|
I'm developping a Winamp visual plugin. I use MFC.
I have a CWinApp derived class (instance is myApp), that has for members init, config, render and quit that are mapped to exported c functions (that Winamp retrieves).
I create a dialog box, instance of a CDialog derived class. I call Create to launch it modelessly. When I close it by the x close button (IDCANCEL) it closes. I can stop the plugin. When i stop Winamp it crashes. When I call DestroyWindow from myApp it crashes.
I tried several solutions : with or without delete in PostNcDestroy, with or without delete from myApp, in a CWinThread derived class, with DestroyWindow in OnCancel or not, and other parameters. There are always problems, depending of those parameters. Most of the time Winamp crashes when the dialog is closed, sometimes some way of closing it works.
Can someone explain how to implement such a CDialog derived class, and how to use it in a modeless way (with a pointer, new, delete and functions such as CreateMyDialog, ShowMyDialog, HideMyDialog, DestroyMyDialog) ?
|
|
|
|
|
Hello people,
I am trying to catch the WM_COMMAND message of a certain button in an external application. Catching works fine with both WH_CALLWNDPROC and WH_CALLWNDPROCRET hooks. But after the catch I want to WM_NULL it, so the app wont actually execute the function that the button calls.
After some browsing through the MSDN, it seems like the WH_GETMESSAGE hook is the only one that can actually modify messages. However, changing my WH_CALLWNDPROC hook to a WH_GETMESSAGE hook resulted in nothing. It seems as if WM_COMMAND never gets processed by WH_GETMESSAGE.
It may be that WH_GETMESSAGE is the wrong hook to catch WM_COMMAND, but then how SHOULD I do it? WH_CALLWNDPROC can't modify the message, only inspect it...
Thanks,
- Fahr
|
|
|
|
|
I'm using the CHtmlEditCtrl class which encapsulates HTML editing function. I would like to be notified when the control gains the focus, so that I could enable some commands.
I've created a devired class, but my new class doesn't get the focus notification!
Here is the declaration of my class:
<br />
#pragma once<br />
#include "afxhtml.h"<br />
<br />
<br />
class CMyHtmlEditCtrl : public CHtmlEditCtrl<br />
{<br />
DECLARE_DYNCREATE(CMyHtmlEditCtrl)<br />
DECLARE_MESSAGE_MAP()<br />
public:<br />
CMyHtmlEditCtrl(void);<br />
virtual ~CMyHtmlEditCtrl(void);<br />
afx_msg void OnSetFocus(CWnd* pOldWnd);<br />
};<br />
and the implemantation file (.CPP):
<br />
#include "StdAfx.h"<br />
#include ".\myhtmleditctrl.h"<br />
<br />
IMPLEMENT_DYNCREATE(CMyHtmlEditCtrl, CHtmlEditCtrl)<br />
<br />
CMyHtmlEditCtrl::CMyHtmlEditCtrl(void)<br />
{<br />
}<br />
<br />
CMyHtmlEditCtrl::~CMyHtmlEditCtrl(void)<br />
{<br />
}<br />
BEGIN_MESSAGE_MAP(CMyHtmlEditCtrl, CHtmlEditCtrl)<br />
ON_WM_SETFOCUS()<br />
END_MESSAGE_MAP()<br />
<br />
void CMyHtmlEditCtrl::OnSetFocus(CWnd* pOldWnd)<br />
{<br />
AfxMessageBox ("Got Focus!");<br />
CHtmlEditCtrl::OnSetFocus(pOldWnd);<br />
}<br />
What is going wrong?
Thks in advance!
Appstmd
http://www.appstmd.com
|
|
|
|
|
Have you checked with Spy++ that WM_SETFOCUS is actually being sent to the control?
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
|
The MSHTML control may be preventing it from being passed on. You could try putting a PreTranslateMessage() into your derived view and/or MainFrm.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Thks for your answer. Even in the PreTranslateMessage, I can't receive the WM_SETFOCUS message! Where is the pb?
<br />
BOOL CMyHtmlEditCtrl::PreTranslateMessage(MSG* pMsg)<br />
{<br />
if (pMsg->message==WM_SETFOCUS)<br />
AfxMessageBox ("Focus!");<br />
<br />
return CHtmlEditCtrl::PreTranslateMessage(pMsg);<br />
}
Thks in advance!
Appstmd
http://www.appstmd.com
|
|
|
|
|
|
Thks for your help!
I will explore the web sites you give me.
When the control gets focus, I see that it receives the 0x0118 message, but I don't have further information about this message. I will use it instead of WM_SETFOCUS.
Appstmd
http://www.appstmd.com
|
|
|
|
|
Appstmd wrote:
I see that it receives the 0x0118 message
This appears to be undocumented so using it is not wise.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
This is for an MDI program (mfc) with visual c++ 6.0
Probably a pretty easy question:
I am using CFileDialog for open/save as file operations. I want to be able to create an instance of the dialog, change the working directory in code at runtime, and then domodal() having the dialog show the directory i specified as the current directory. I'm able to get the directory names i want to use in the format CString (i.e. "c:\project\dbc") and i want to use this path/directory string to change the directory but i can't seem to figure out how to do it.
Jeff Rothenberg
Project Engineer
Vector CANtech, Inc.
|
|
|
|