|
I'm creating a couple of debugging text files from a DLL and I need these to appear only in the same directory as the DLL. I have been using GetCurrentDirectory() to determine the path and appending the filenames to that. This works fine with my test application. However, with the release application (which I have no control over), the files are created on the desktop. Is this because the application is changing the current directory? Both the application and the DLL are in the same directory (usually: c:\program files\...)
So, is there a way to determine the full path to the DLL from within the DLL and not worry about the current directory?
Thanks
|
|
|
|
|
|
Try GetModuleFileName()
Art
|
|
|
|
|
I use the following..
_TCHAR drive[_MAX_DRIVE];
_TCHAR dir [_MAX_DIR];
_TCHAR fname[_MAX_FNAME];
_TCHAR ext [_MAX_EXT];
_TCHAR path [_MAX_PATH];
GetModuleFileName(NULL, path, _MAX_PATH);
_tsplitpath(path, drive, dir, fname, ext);
CString strCurrentDir = CString(drive) + dir;
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
Thanks for all the help. I've got things working just fine now.
|
|
|
|
|
I would like to have a SOAP server that would require a client certificate to authenticate the client machines. On the client side, I use the CSecureEvtSyncSocket class. For those who know that class, there is a while loop in the clientHandshakeLoop method of that class.
Here is a part of that loop:
scRet = SEC_I_CONTINUE_NEEDED;
while(scRet == SEC_I_CONTINUE_NEEDED ||
scRet == SEC_E_INCOMPLETE_MESSAGE ||
scRet == SEC_I_INCOMPLETE_CREDENTIALS)
{
scRet = g_Sample_SecurityInit._SecurityFunc.InitializeSecurityContext(&m_hClientCreds,
&m_hContext,
NULL,
dwSSPIFlags,
0,
SECURITY_NATIVE_DREP,
&InBuffer,
0,
NULL,
&OutBuffer,
&dwSSPIOutFlags,
&tsExpiry);
if(scRet == SEC_I_INCOMPLETE_CREDENTIALS)
{
getNewClientCredentials();
fDoRead = FALSE;
scRet = SEC_I_CONTINUE_NEEDED;
continue;
}
}
I configured IIS on the SOAP server to require Client Certificates. I know this should because the application works if this is not set, and returns errors if it is set.
The first call to InitializeSecurityContext returns SEC_I_CONTINUE_NEEDED but the second pass returns 0 . What I don't understand, is why the call to InitializeSecurityContext never returns SEC_I_INCOMPLETE_CREDENTIALS which would indicate to the client that a client certificate is required.
Also, I would like to know if there is an article, preferably on CP , on how to manage client certificates, both on client and server, and how to access them programmatically.
Tx
|
|
|
|
|
1)Is it OK if I do nothing in the constructor – all initializations are done in the initialization list and the body of the Ctor is empty, i.e {}?
2)In one of the class methods I open, read and close a file. In another one I open, write and close an other file. Should I do something in the destructor? I have no class members for these streams so… In any case, Is it OK to leave a Dtor empty (actually not even declaring a Dtor) if there is no allocation on the heap throughout the class (no ‘new’)?
Thanks.
-----------------------
Go USA Go
|
|
|
|
|
1. yes
2. yes, you can leave the dtor empty. as long as your file objects are locals (and so,get cleaned up).
-c
Image tools: ThumbNailer, Bobber, TIFFAssembler
|
|
|
|
|
Makover wrote:
1)Is it OK if I do nothing in the constructor – all initializations are done in the initialization list and the body of the Ctor is empty, i.e {}?
Granted no initialization can throw an exception, yes.
IMHO, this style is ugly, but it's only a matter of personal taste, no problem at all.
Makover wrote:
2)In one of the class methods I open, read and close a file. In another one I open, write and close an other file. Should I do something in the destructor? I have no class members for these streams so… In any case, Is it OK to leave a Dtor empty (actually not even declaring a Dtor) if there is no allocation on the heap throughout the class (no ‘new’)?
Assuming it's a base class, yes. But it's a good practice to declare a virtual destructor on each class, even if empty, this will save you some headaches in the future and will introduce no overhead (or almost no overhead, depending on your compiler).
It's not the fall that kills you: it's the sudden stop - Down by Law, Jim Jamursch (1986)
|
|
|
|
|
Thank You Chris and Daniel,
Daniel Turini wrote:
IMHO, this style is ugly, but it's only a matter of personal taste, no problem at all.
I think so too. Would it be right if I skip the initialization list and do all initialization in the body of the Ctor?
Daniel Turini wrote:
But it's a good practice to declare a virtual destructor on each class, even if empty, this will save you some headaches in the future and will introduce no overhead (or almost no overhead, depending on your compiler).
IS this overhead the Virtual Table? Should I declare my Dtors virtual, even if no virtual methods exist in my class?
Have a quiet week-end
-----------------------
Go USA Go
|
|
|
|
|
Makover wrote:
I think so too. Would it be right if I skip the initialization list and do all initialization in the body of the Ctor?
Depends if you have const member variables, they need to be set in the init list.
M.
Maximilien Lincourt
For success one must aquire one's self
|
|
|
|
|
Yes, const and reference types must be initialized in the iniatializer list. It's actually a good idea to initialize all members there, since it's also a little more efficient than doing it inside the body of the constructor.
Regards,
Alvaro
That which does not kill me postpones the inevitable. -- despair.com
|
|
|
|
|
There is a performance hit when you initialize member variables outside of the init list. Instead of the variable getting initialized with the proper value, it gets initialize and then a new value set. However, for many types of member variables this really isn't an issue since the ctor does nothing at all (i.e. an "int" member variable.)
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
While you can skip the initialization list and do all of the initialization in the body of the constructor, it is actually a good habit to get into to try to initialize anything that you can using the initializer list.
It doesn't make any difference for simple data types (ints, doubles, etc), but if you have any member variables which have default constructors and also need to be initialized to some value, you end up doing extra work. The compiler will call the default constructor for any members which aren't listed in the initializer list, and then you will assign a value to the member in the body of the constructor.
|
|
|
|
|
I need my add-in sends a similar build that Visual Studio does (with F7).
That is to say, for each workspace loaded in the VS builds all the projects for all its configurations.
what can i do?
Thank you !
|
|
|
|
|
Hi,
I'm trying to send one email with on attachment, via outlook automation, my code is:
COutlookApplication& App = COutlookApplication::Instance();
Outlook::_MailItemPtr pMail = App.CreateMailItem();
pMail->To = (LPCSTR) m_sTo;
pMail->CC = (LPCSTR) m_sCopyTo;
pMail->Subject = (LPCSTR) m_sSubject;
pMail->Body = (LPCSTR) m_sBody;
COleVariant Param((long) Outlook::olByReference);
COleVariant Position((long) 0);
_bstr_t DisplayName = "whatever";
_bstr_t Path = "C:\\Delete\\test.doc";
Outlook::AttachmentsPtr pAtt = pMail->Attachments;
pAtt->Add(Path, Param, Position, DisplayName);
pMail->Send();
The result that I get... Email in the outbox... but.. with no attachment ... anyone knows what can be the reason ?
Thanks in advance, Greetings
Braulio
|
|
|
|
|
Well... now I just tried...
Outlook::AttachmentsPtr pAtt = pMail->Attachments;
pAtt->Add(L"c:\\download\\MyStuff.htm");
and it worked out... maybe can be beause it's not a binary file... ?
shhh.....
|
|
|
|
|
Hello,
this is (I think) the stupidest question I've posted here...
but, and only for curiosity...
I've designed an app with bitmapped background and I have been trying to make a bitmapped button to coincide with the background, but it seemed to be impossible, using mouse or using keys...
I've finished moving the button control in the OnInit dialog handler using this code:
this->m_cbtnCintaTransportadora.GetWindowRect(&rCorreccioPosBtnCintaTransportadora);
rCorreccioPosBtnCintaTransportadora.left += 1;
rCorreccioPosBtnCintaTransportadora.right +=1;
rCorreccioPosBtnCintaTransportadora.top+=1;
rCorreccioPosBtnCintaTransportadora.bottom+=1;
ScreenToClient(&rCorreccioPosBtnCintaTransportadora);
this->m_cbtnCintaTransportadora.MoveWindow(rCorreccioPosBtnCintaTransportadora);
Is it possible to do it via the dialog editor?
Thank you in advance...
|
|
|
|
|
Hi Joan,
Are you saying you have a background with a pattern on it and your button needs to line up with the background pattern? Or are you just trying to place the button using the resource editor?
I have used bitmap backgrounds on dialog boxes extensively. I always use CBitmapButton class for the buttons. You drag the regular buttons onto the dialog from the resource palette as usual but you only have control of the left top corner of the button. The rest is controlled by the actual size of the bitmap of the button.
If there is a problem with the pattern I reposition in the editor or make an adjustment in a image editor.
Art
|
|
|
|
|
I was talking about placing a bitmap (picture control) in the dialog and then different Bitmap buttons over it (by changing the showing order).
is there any way to place the bitmap in teh dialog? what is a pattern (in this context)?
thank you in advance...
|
|
|
|
|
I would avoid the picture control method of putting the bitmap on the dialog background.
Do this instead:
//Declare some variables:
CBrush m_brush;
CBitmapButton m_btnOK;
CBitmapButton m_btnCancel;
//Add code:
OnInitDialog:
{
...
RECT rc;
GetClientRect(&rc);
HBITMAP hBmp=NULL;
hBmp=(HBITMAP)::LoadImage(NULL,"YourPath.bmp",IMAGE_BITMAP,rc.right,rc.bottom,LR_LOADFROMFILE);
CBitmap *pBmp=CBitmap::FromHandle(hBmp);
m_brush.CreatePatternBrush(pBmp);
::DeleteObject(hBmp);
// Load Graphics onto OwnerDrawn buttons.
// These are CBitmapButton objects
m_btnOK.AutoLoad(IDOK,this);
m_btnCancel.AutoLoad(IDCANCEL,this);
}
OnPaint()
{
//Paint the background with the image brush
CRect rcClient;
GetClientRect(&rcClient);
dc.FillRect(&rcClient,&m_brush);
}
OnCtlColor(..)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
switch(nCtlColor)
{
case CTLCOLOR_STATIC:
pDC->SetTextColor(RGB(TBD));
case CTLCOLOR_BTN:
pDC->SetBkMode(TRANSPARENT);
case CTLCOLOR_DLG:
hbr=m_brush;
}
return hbr;
}
Art
|
|
|
|
|
WONDERFUL: easy and much better.
Only one question:
this is a pattern (now I understand what you were talking about) is there any way to load the bitmap without making a pattern? only load it one time?
Thank you in advance.
|
|
|
|
|
Joan,
(..only load it one time?)
You are loading it only one time. LoadImage(..) is called only once. I don't understand the question.
Art
|
|
|
|
|
Nothing, I meant that if the dialog gets resized the background image gets repeated until the background is fullfilled...
I'd like to get the image not resized and aligned only to top left...
is it possible to get the image sized as the original? even if the dialog gets resized?
thank you in advance...
|
|
|
|
|
Sorry, I thought you wanted it as a background on your dialog.
What you need to do is change the code in OnPaint. This is where the size of the image is being computed when the dialog is resized. Instead of GetClentRect(..) just specify the fixed size of the rectange you want to fill in the FillRect(..)
OnPaint(..)
//Paint the background with the image brush
//CRect rcClient; //Modify this to be the rectangle you want
//GetClientRect(&rcClient); //Block this
dc.FillRect(&rcClient,&m_brush);
Art
|
|
|
|