|
VCSharp007 wrote: I have a requirement to add a CArray member varibale in my class without including
afxtempl.h in my class header file.
template<class TYPE, class ARG_TYPE> class CArray;
class SomeClass
{
public:
CArray<float, float>* pFloatArray = 0;
};
|
|
|
|
|
Thanks Nibu.
But I have to use CArray varibale not pointer!!!!
|
|
|
|
|
VCSharp007 wrote: But I have to use CArray varibale not pointer!!!!
No then forward declaration won't work, since classes should know their sizes. Pointer is ok since size will be sizeof a pointer.
Forward declaration just tells the compiler that the class is ok and definition of that is readily available somewhere. So it searches for the given class when code for the parent class is being generated.
Otherwise include "afxtempl.h" in precompiler header file. But then again there will be issues when this header file is being used somewhere else where there is no precompiled header file.
|
|
|
|
|
This is a bad requirement, because than is the dependency unclear.
Remember: Write selfexplaining code, so you dont need to document the code.
You can also include the afxtempl.h in another header. stdafx.h is a good place because, the afxtempl.h wont be change a lot of times.
Greetings from Germany
|
|
|
|
|
I am trying to do it with MSI , but i do something wrong in the code below , publisher names dont always match with product names , can you browse it ?
Function just fills struct :
#define VERSION_LEN 16
#define CODE_LEN 39
#define NAME_LEN 256
#define PUBLISHER_LEN 256
#define PATH_LEN 256
#define MSI_LEN 256
typedef struct _INSTALLED_SOFTWARE_INFORMATION
{
BOOL bManaged ;
BOOL bPerMachine ;
char wszProductCode[CODE_LEN] ;
char wszProductName[NAME_LEN] ;
char lpVersion[VERSION_LEN] ;
char lpPublisher[PUBLISHER_LEN];
char lpPath[PATH_LEN];
char lpMSI[MSI_LEN];
ERROR_DATA errData ;
}INSTALLED_SOFTWARE_INFORMATION ;
int GetInstalledProducts(INSTALLED_SOFTWARE_INFORMATION* pSwInformation,unsigned int* nCount)
{
DWORD dwIndex = 0;
UINT uiStatus ;
char assignment_type[10] = {0} ;
char lpVersion[VERSION_LEN] = {0} ;
char lpProducts[NAME_LEN] = {0} ;
char lpPublisher[PUBLISHER_LEN] = {0};
char lpPath[PATH_LEN]= {0};
char lpMSI[MSI_LEN]= {0};
DWORD cchAssignmentType ;
DWORD cchVersionName ;
DWORD cchPublisher;
DWORD cchProductName;
DWORD cchPath ;
DWORD cchMsi;
for(;;)
{
uiStatus = MsiEnumProducts(dwIndex,pSwInformation[dwIndex].wszProductCode);
uiStatus = MsiIsProductElevated( pSwInformation[dwIndex].wszProductCode,&( pSwInformation[dwIndex].bManaged ));
uiStatus = MsiGetProductInfo(pSwInformation[dwIndex].wszProductCode,INSTALLPROPERTY_ASSIGNMENTTYPE,assignment_type,&cchAssignmentType) ;
if(uiStatus !=ERROR_SUCCESS )
{
switch(uiStatus)
{
// return FALSE ;
}
}
else
{
if(assignment_type[0] == '1' )
pSwInformation[dwIndex].bPerMachine = TRUE ;
else
pSwInformation[dwIndex].bPerMachine = FALSE ;
}
uiStatus = MsiGetProductInfo(pSwInformation[dwIndex].wszProductCode,INSTALLPROPERTY_PRODUCTNAME,lpProducts,&cchProductName);
strcpy(pSwInformation[dwIndex].wszProductName,lpProducts);
uiStatus = MsiGetProductInfo(pSwInformation[dwIndex].wszProductCode,INSTALLPROPERTY_VERSIONSTRING,lpVersion,&cchVersionName);
strcpy(pSwInformation[dwIndex].lpVersion ,lpVersion);
uiStatus = MsiGetProductInfo(pSwInformation[dwIndex].wszProductCode,INSTALLPROPERTY_PUBLISHER,lpPublisher,&cchPublisher);
strcpy(pSwInformation[dwIndex].lpPublisher ,lpPublisher);
uiStatus = MsiGetProductInfo(pSwInformation[dwIndex].wszProductCode,INSTALLPROPERTY_INSTALLSOURCE ,lpPath,&cchPath);
strcpy(pSwInformation[dwIndex].lpPath ,lpPath);
uiStatus = MsiGetProductInfo(pSwInformation[dwIndex].wszProductCode,INSTALLPROPERTY_PACKAGENAME ,lpMSI,&cchMsi);
strcpy(pSwInformation[dwIndex].lpMSI ,lpMSI);
dwIndex++;
*nCount = dwIndex ;
}
EXIT :
return dwIndex ;
}
|
|
|
|
|
Hi everybody. I got a tiny question about a strange problem I'm having when I'm trying to receive a string from Visual Basic into C++. I got a VB string saying "Arial". But when I'm receiving it in C++, it becomes "Ail". Probably some wide characters versus normal characters problem, as i get 1 character and the next not, and then the next, I get. In order to make the conversion I'm using these two functions.
<br />
<br />
long GetLengthOfBSTR (BSTR Target)<br />
{<br />
long iRet = 0;
long iCursor = 0;
bool bForever = false;
<br />
if (Target == NULL)<br />
return(0);
while (!bForever)
{<br />
unsigned int uiPiece = Target[iCursor];
if (uiPiece == 0)<br />
return(iRet);
else<br />
iRet++;
iCursor++;
}<br />
return -1;
}<br />
<br />
char *ConvertBSTRToChar (BSTR Target)<br />
{<br />
char *sResult;
long iCounter;
long iLength;
<br />
iCounter = iLength = GetLengthOfBSTR(Target);
sResult = new char[iLength + 1];
strcpy(sResult, "");
for (iCounter = 0; iCounter < iLength; iCounter++)
{<br />
unsigned int uiPiece = Target[iCounter];
sResult[iCounter] = uiPiece;
sResult[iCounter + 1] = '\0';
}<br />
return sResult;
}<br />
And then I do:
<br />
LPCSTR c;<br />
c = ConvertBSTRToChar(StuffFromVB);<br />
MessageBox(0, c, "Test", 0);<br />
SO? Anybody here to enlighten me a bit about this? : ). Thank you very much for your time here anyway!
|
|
|
|
|
Why do you have to roll out convertion functions for BSTR's on your own. We already have ConvertStringToBSTR and ConvertBSTRToString . Why not use them. Link to comsupp.lib for using them.
|
|
|
|
|
<br />
LPCSTR d = _com_util::ConvertBSTRToString(FontInformation.Name);<br />
MessageBox(0, d, 0, 0);<br />
This still returns garbage data : ( ... what do you make of: "???r" instead of "Arial". And it's sure that it's a BSTR there. For example, my function works but doesn't process the BSTR correctly. It would be easier for me to fix my function ... if only I knew what's wrong : D.
|
|
|
|
|
Axonn Echysttas wrote: This still returns garbage data : ( ... what do you make of: "???r" instead of "Arial". And it's sure that it's a BSTR there. For example, my function works but doesn't process the BSTR correctly. It would be easier for me to fix my function ... if only I knew what's wrong : D.
Watch memory for this variable to see if the contents is in the variable as you expect it to be.
|
|
|
|
|
Your functions are wrong. Note that a bstr is not required to be null terminated. If you want to get the size of a BSTR, use for example wcslen. To convert between BSTR and C-style strings, use
W2A, OLE2A macros from <AtlBase.h>. Also see CComBSTR class.
--
=====
Arman
|
|
|
|
|
I replaced with wcslen and still same problem. I would prefer to understand how to convert it corectly, manually. That way I don't have to depend on more links and stuff that can break from one windows release to the other : ).
|
|
|
|
|
|
|
Arman Z. Sahakyan wrote: Note that a bstr is not required to be null terminated.
Actually BSTR is terminated by double byte NULL. \0\0
Best Wishes,
-David Delaune
|
|
|
|
|
Hi,
Try using:
<br />
template<class T> BSTR ConvertToBSTR(T a_Str) <br />
{<br />
return(_bstr_t(a_Str).copy());<br />
}<br />
It's the same function I posted in your article two years ago.
Best Wishes,
-Randor (David Delaune)
|
|
|
|
|
Hhahahaah, Hi : D. That should be a lesson to me huh? To better remember stuff.
Hm, however, this is to return a BSTR, I need the other way around. A Char from a BSTR. : D.
|
|
|
|
|
Hi again,
The _bstr_t has a built-in char* operator. So this means you can just do something like this:
<br />
BSTR test;<br />
char buffer[SOME_LENTH];<br />
_bstr_t bstr(test,true);<br />
strcpy(buffer,(char*)bstr);<br />
The above code does not check buffer length. A simple new/delete using the BSTR length should take care of that.
Best Wishes,
Randor (David Delaune)
|
|
|
|
|
What's very interesting is that I managed to solve everything just like this:
LPCSTR a = (LPCSTR)myBSTR;
MessageBox(0, a, 0, 0); //-> it works, if you can believe it!!! Probably because I send only non-Unicode stuff from VB. Anyway, this is how it's gonna stay for a while and I don't intend to ever switch this program to Unicode. Works just fine like it is.
|
|
|
|
|
When I display the dialog created by CPropertySheet::DoModal, some other window in background is coming between the proprty sheet dialog and application. After clicking "OK" or "Cancel" of dialog the application is getting the focus. But Can I avoid other window coming between main window and dialog?
Best Regards,
Suman
|
|
|
|
|
Can you tell, how third window is associated with this application ?
Prasad
MS MVP - VC++
|
|
|
|
|
The third window may be the windows explorer or any application.
Before displaying property sheet, if there is any changes in GUI data,
I am updating data with progress dialog created by thread. After the progress finish,
I am calling DestroyWindow()of progress dialog and then displaying property sheet.
The third window is coming between application and property sheet after the DestroyWindow() of dialog.
Best Regards,
Suman
|
|
|
|
|
I work with Visual C++ (at the moment in Visual Studio2005). I have a resizable dialog bar - from a class I derived from CDialog bar to be resiable. When i am resizing (reducing) the main window the dialog bar is also resizing but after a certain point dialog bar disappears, And it visible only after resizing the (increasing) the main window. What i want is that after a certain point user should not be able to resize the window any more. How do i do that ?
Sandip
|
|
|
|
|
g_sandipan wrote: What i want is that after a certain point user should not be able to resize the window any more. How do i do that ?
Override afx_msg void OnGetMinMaxInfo( MINMAXINFO* lpMMI ) by handling WM_GETMINMAXINFO and fill out lpMMI->ptMinTrackSize with minimum height and width.
|
|
|
|
|
Thanks Nibu. Its Working fine
Sandip
|
|
|
|
|
Excuse me if I post in the wrong place but I'm having a very wierd problem.
I have an application written with MFC. Basically, it has around 10 worker threads doing smth continuously and post message to CMainFrame when done. The MainFrame will process these messages and update some list control on GUI. Simple, isnt' it?
Originally, I test and deploy my application on a Windows XP SP2 machine with CPU Celeron 2,4GHz. It runs well although it consumes 40-50% CPU all the time.
Now, I have a server with CPU Xeon 3GHz, 1GB RAM, SCSI hard disk with RAID 1 (seems to be an overkill hah). On this server, my application only consumes 5% CPU but it runs LIKE HELL. It takes ages for me to access menu items and do other things on the GUI. In other word, the GUI seems to be frozen regularly. I don't know what's going on !!!
I guess that because windows server 2003 has some mechanism to schedule and distribute CPU between applications. I have tried to config Processor scheduling & memory usage to best performance for program, it helps improves a bit, but still far from what's shown on the old Celeron computer !!! Setting process priority into "real time" in task manager also doesn't help.
I'm clueless now, any one please help me
|
|
|
|
|