|
I wish to use ofstream::seekp() to point and set
there the new EOF, but...
I tried:
{
ofstream o("blah.txt", ios::in | ios::out);
o.seekp(-30L, ios::end);
//set the ptr 30 bytes back from EOF.
//I want to set (the new) EOF HERE!
}
10x.
|
|
|
|
|
I think you're better off telling us what you're trying to accomplish. I'm sure there's another way to solve the problem. Trying to set the EOF yourself is a losing proposition.
|
|
|
|
|
In another words, I wish to shorten the file, in 'n' bytes.
I wish to delete a stream of a known size and position,
from the end of the file.
Thanks again!
*** Bar Cochva _@_y ***
|
|
|
|
|
I'm coding in Borland C++ Builder 5...
I want to change what the executable name is when my project compiles.
Also I want to be able to have my program centered on screen when it's
compiled, so when people use it with different resolutions and what not, it's still starts in the center of the screen.
Any help would be much appreciated.
Thanks,
Aaron
|
|
|
|
|
First one is set in PRoject/Settings/Link, the second is CenterWindow();
Christian
#include "std_disclaimer.h"
The careful application of terror is also a form of communication.
Eagles may soar, but weasels don't get sucked into jet engines.
|
|
|
|
|
Perhaps i have a problem with my brain, but i would like to know if the a default constructor must do sthing. I explain what i mean.
In my application, i have created a class where of course there is a constructor, mine is a default constructor. I don't need to create an object which will be initialize to something, i just want to have some methods which do calculations..., so in my code .cpp, i put nothing between curly brace for the definition of the constructor. Is it good or not?
thanks in advance
gerald
|
|
|
|
|
if the ctor does nothing, then dont bother coding one, the compiler will do it for you.
|
|
|
|
|
Greetings!
I know for a fact that you can not call the SendMessage function from CDocument since it is not derived from CWnd. But is there any other way
to get around this?
In the ff. example I would like to use CDocument instead of CView:
--------------------------------------------------------------------
LRESULT CMainFrame::OnDialogDestroyed (WPARAM wParam, LPARAM lParam)
{
CView* pView = GetActiveView();
pView->SendMessage(WM_USER_DIALOG_DESTROYED, wParam, lParam);
return 0;
}
--------------------------------------------------------------------
Many thanks!
|
|
|
|
|
use the SDK version SendMessage(HWND , UINT, ...)
and use the handle for your frame window (CFrameWnd).
From there, when the message is received, route it to
the doc (call a document function, whatever).
|
|
|
|
|
I'm used to Borland, where you can just drop a tab control in the visual environment, then select each tab in turn and drop controls onto the tabs just like you do with a normal dialog. It doesn't seem possible to do this with VC++, or have I missed something? Can anyone point me in the direction of a simple guide to creating a tabbed dialog app?
Dave
Dave
|
|
|
|
|
I had used Borland once and the list of things that could not be done was too long.
Borland == Visual Basic for C++
Anyway, no you can't drop controls on the seperate tabs (at least that I'm aware of). You would have to place them in the dialog editor and then handle the change tab message to show or hide the appropriate controls.
|
|
|
|
|
|
Good point. I thought about PropertySheet/PropertyPage after I hit submit.
|
|
|
|
|
The solution described in this article doesn't use propsheets or proppages, no matter how they titled it. They just create a tab control and host child dialogs inside ('real' propsheet uses similar method). When tabs are clicked, hosted dialog is replaced by another 'page'.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Hello,
I want to create my mainframe with a certain size. Right now I have overridden CMainFrame::PreCreateWindow and I set the members of the CREATESTRUCT x,y,cx and cy to hardcoded values.
I would however like to do this properly, by using AdjustWindowRect(Ex) to calculate the values for me.
The whole point is I want the client area to be of zero height, like the Visual Basic development environment used to be.
I cannot make this work. Here is my code:
BOOL COptixFrmMain::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style &= ~WS_MAXIMIZEBOX;
// cs.style &= ~WS_THICKFRAME;
// cs.style &= ~WS_SYSMENU;
/* These values are the ones I want!
cs.x = 0;
cs.y = 0;
cs.cx = 450;
cs.cy = 105;
*/
RECT rect;
SetRectEmpty(&rect);
rect.right = 450; // I want it to be 450 wide
::AdjustWindowRect(&rect,cs.style,TRUE);
cs.x = 0;
cs.y = 0;
cs.cx = rect.right - rect.left;
cs.cy = rect.bottom - rect.top;
cs.lpszClass = AfxRegisterWndClass(
CS_DBLCLKS, // if you need double-clicks
NULL, // no cursor (use default)
NULL, // no background brush
AfxGetApp()->LoadIcon(IDR_MAINFRAME)); // app icon
ASSERT(cs.lpszClass);
if( !SECFDIFrameWnd::PreCreateWindow(cs) )
return FALSE;
return TRUE;
}
If you look carefully, you can see that I use Objective Toolkit, and their FDI classes, but that should hardly matter in this case.
All help is appreciated!
************************
Peter Andersson
peter.andersson@dtsag.ch
|
|
|
|
|
Objective Toolkit should hardly matter. You would be surprised. We gave up on using Stingray for our projects because they had so many features we had to work around. I recently had another project that used a Stingray tree control that gave some strange runtime errors. I eventually tracked it to the fact that while I expected a NULL to be returned in some cases it was not. I took Stingray out of the picture and everything worked perfectly.
|
|
|
|
|
I think you are right. A small testprogram shows that AdjustWindowRect does not understand the StingRay tear-off menu.
However, the std MFC testprog works fine, except for not noticing the toolbar. How do I find the height of that one?
Peter
************************
Peter Andersson
peter.andersson@dtsag.ch
|
|
|
|
|
You can use the following VB Script to create a project:
Set objMSDEV = WScript.CreateObject("msdev.application")
objMSDEV.addproject "test","c:\myapp",TRUE
objMSDEV.ActiveProject.AddFile "test.cpp"objMSDEV.QuitWScript.Echo "Done"
From this I have determined that the following C++ code should also generate a project:
#include "stdafx.h"
#include <stdio.h>
#include <atlbase.h>
extern CComModule _Module;
#include <atlcom.h>
#include <initguid.h>
#include <comdef.h>
#include <ObjModel\appauto.h>
#include <ObjModel\appdefs.h>
#include <ObjModel\appguid.h>
#include <ObjModel\bldauto.h>
#include <ObjModel\bldguid.h>
#include <ObjModel\blddefs.h>
#include <ObjModel\textauto.h>
#include <ObjModel\textguid.h>
#include <ObjModel\textdefs.h>
#include <ObjModel\dbgauto.h>
#include <ObjModel\dbgguid.h>
#include <ObjModel\dbgdefs.h>
IApplication *pApp;
int main(int argc, char* argv[])
{
HRESULT hr = CoInitialize(NULL);
if(FAILED(hr))
{
printf("Failed to initialize the COM libraries\n");
return FALSE;
}
hr = CoCreateInstance(CLSID_Application, NULL, CLSCTX_LOCAL_SERVER, IID_IApplication, (void**)&pApp);
if(FAILED(hr))
{
printf("Failed to create an instance of MSDEV\n");
CoUninitialize();
}
CComBSTR bProjectName("project");
CComBSTR bPath("c:\\myproject");
CComBSTR bType("Application");
VARIANT_BOOL bCreateDirs=VARIANT_FALSE;
pApp->AddProject(bProjectName,bPath,bType,bCreateDirs);
pApp->Quit();
pApp=NULL;
CoUninitialize();
return 0;
}
The problem is the call to add the project generates the following error:
Debug Error!
Program: test.exe
Module:
File: i386\chkesp.c
Line: 42
The value of ESP was not properly saved accross a function call.
This is usually a result of calling a function declared with one
calling convention with a function pointer declared with a different
calling convention.
Can any body tell me what I am doing wrong?
Thanks for any help you can provide.
Steve.
|
|
|
|
|
I don't see a pApp->Release() call being made. Not sure if that's the problem though....
HTH
Jignesh
|
|
|
|
|
The error comes from the call to pApp->AddProject() so I dont get far enough to make a call to pApp->Release(), but thanks for trying.
|
|
|
|
|
I think this has something to do with IDispatch vs IUnknown - IApplication is a dual interface, so I decided to try using IDispatch::Invoke instead of calling the AddProject interface directly:
#include <stdio.h>
#include <atlbase.h>
extern CComModule _Module;
#include <atlcom.h>
#include <initguid.h>
#include <comdef.h>
#include <ObjModel\appauto.h>
#include <ObjModel\appdefs.h>
#include <ObjModel\appguid.h>
int main(int argc, char* argv[])
{
HRESULT hresult = CoInitialize(NULL);
if(FAILED(hresult))
{
printf("Failed to initialize the COM libraries\n");
return FALSE;
}
IUnknown FAR* punk;
IDispatch FAR* pdisp = (IDispatch FAR*)NULL;
DISPID dispid;
hresult = CoCreateInstance(CLSID_Application, NULL, CLSCTX_SERVER,
IID_IUnknown, (void FAR* FAR*)&punk);
if(FAILED(hresult))
{
printf("Failed to create an instance of MSDEV\n");
CoUninitialize();
}
hresult = punk->QueryInterface(IID_IDispatch,
(void FAR* FAR*)&pdisp);
OLECHAR FAR* szMember = L"AddProject";
hresult = pdisp->GetIDsOfNames(IID_NULL, &szMember, 1,
LOCALE_USER_DEFAULT, &dispid);
VARIANT varResult;
EXCEPINFO excepInfo;
unsigned int uArgErr;
DISPPARAMS dispparams;
dispparams.rgvarg = new VARIANT[4];
CComBSTR bstrProjectName("project");
CComBSTR bstrPath("c:\\myproject\\project");
CComBSTR bstrType("Application");
dispparams.rgvarg[0].vt = VT_BOOL;
dispparams.rgvarg[0].boolVal = VARIANT_TRUE;
dispparams.rgvarg[1].vt = VT_BSTR;
dispparams.rgvarg[1].bstrVal = bstrType;
dispparams.rgvarg[2].vt = VT_BSTR;
dispparams.rgvarg[2].bstrVal = bstrPath;
dispparams.rgvarg[3].vt = VT_BSTR;
dispparams.rgvarg[3].bstrVal = bstrProjectName;
dispparams.cArgs = 4;
dispparams.cNamedArgs = 0;
hresult = pdisp->Invoke(
dispid,
IID_NULL,
LOCALE_USER_DEFAULT,
DISPATCH_METHOD,
&dispparams, &varResult, &excepInfo, &uArgErr);
if(DISP_E_EXCEPTION == hresult) {
_bstr_t bt(excepInfo.bstrDescription);
printf("VC Exception: %s\n", (char*)bt);
}
szMember = L"Quit";
hresult = pdisp->GetIDsOfNames(IID_NULL, &szMember, 1,
LOCALE_USER_DEFAULT, &dispid);
dispparams.cArgs = 0;
hresult = pdisp->Invoke(
dispid,
IID_NULL,
LOCALE_USER_DEFAULT,
DISPATCH_METHOD,
&dispparams, &varResult, &excepInfo, &uArgErr);
pdisp->Release();
punk->Release();
delete [] dispparams.rgvarg;
CoUninitialize();
return 0;
}
Pretty ugly, but seems to work. The docs and samples for this are a bit lacking, and somebody stole borrowed my copy of Essential Com, so I don't know if this is the only way this can be done.
I guess the theory here is that the interface is intended to be invoked through IDispatch, and problems show up if parameters need to be passed when using AddProject directly.
Would appreciate if someone could verify or debunk said theory.
-----
"They put the COM in COMplicated"
|
|
|
|
|
Thankyou very much for the information.
|
|
|
|
|
I would suggest to use the #import statement on your typelibrary/dll and call COM by using the IApplicationPtr smart pointer that this import statement creates for you.
-Nick-
|
|
|
|
|
Ah! Good idea - actually, article Q247035 discusses both methods, but neither seems at first glance what I would call elegant.
Using #import, this is about the simplest I could come up with - please excuse the strange err handling...
#include "stdafx.h"
#include <atlbase.h>
#import "devshl.dll"
using namespace DSSharedObjects;
int main(int argc, char* argv[])
{
HRESULT hr = CoInitialize(NULL);
if(FAILED(hr)) {
_asm int 3;
}
DSSharedObjects::IApplicationPtr pIApp;
hr = pIApp.CreateInstance("MSDEV.Application");
if(FAILED(hr)){
_asm int 3;
}
_bstr_t bstrProjName("myproject");
_bstr_t bstrPath("e:\\project\\myproject");
_bstr_t bstrType("Application");
VARIANT_BOOL bCreateDirs = VARIANT_TRUE;
hr = pIApp->AddProject(bstrProjName, bstrPath, bstrType, bCreateDirs);
if(FAILED(hr)) {
_asm int 3;
}
pIApp->Quit();
return 0;
}
But it looks to me like this automation will be obsolete with VS.NET - I just started looking at beta 2 and there are no ObjModel headers, and no devshl.dll.
|
|
|
|
|
Thanks again for helping me with my problem. I managed to get this method working last night (this morning technically). I am now trying to figure out how to add source and header files to the project.
Steve.
|
|
|
|
|