mfc >> C++ Question

by Practical Soul » Tue, 01 Jul 2003 12:26:34 GMT

Hi,

Iam using a MS Flexgrid to display some information. I
have derived a class called "CGrid" from "CMSFlexGrid".
Now, my problem is that while I can access all the public
methods of CMSFlexgrid in CGrid, Iam not able to add and
use any new member variables in my derived class, CGrid.
Any idea why? Pls see the code snippet for the class
declaration.

#include "msflexgrid.h"

class CGrid : public CMSFlexGrid
{
public: //Member functions
void SetHeader(int nCol, CString strText);
void Refresh();
void InsertRowAtTop();
void AppendRow();
void SetCellText(int nRow, int nCol, CString
strText);
void Init(void);
void SetDefaultProperties(void);
void SortGrid(void);
CGrid();
virtual ~CGrid();

private: //Member variables
int m_Rows;
int m_Cols;
int m_nSortOrder;
};

It throws a run-time error when I set the values of the
private member variables in the member functions of
CGrid. When I comment out the statements, it works fine.


mfc >> C++ question

by MFC » Mon, 29 Aug 2005 01:03:09 GMT


I want to set all the member variables of a C++ object to 0, Can I do
memset(this , 0 , sizeof(*this)) in the constructor?





mfc >> C++ question

by David Lowndes » Mon, 29 Aug 2005 02:47:10 GMT

>I want to set all the member variables of a C++ object to 0, Can I do

Not generally.

If your class is composed of plain old data members only (and has no
virtual methods), then you could, but I'd recommend that you
initialise each variable (that needs explicitly initialising)
individually.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq


C++ question

by skasat@gmail.com » Thu, 23 Mar 2006 08:19:37 GMT

I was just going thru some changes in my code and need to write some
thing like this

try{
//some code
//if error
return
}

catch{}

I had a doubt using return statement in my try block...what impact will
it have...



C++ question

by Dan Bloomquist » Thu, 23 Mar 2006 10:53:35 GMT





Of course, the reason for putting 'some code' in a 'try is because
methods of that code are capable of 'throwing. It is a cheap way of
unwinding the stack on an error. If you get to 'if error' then there was
nothing to 'catch and you can return. If the underlying code throws you
will never get to the 'if error'. It will surface at the 'catch. It will
be some other error that you know about at 'if error'. In either case
the stack is even at that point and you can return. It is common to:

try
{
if(...)
return true | false;
//or fall threw past 'catch
}
catch(.. e )
{
...//Warn?
e->Delete( );
return false;
}
return true;

Best, Dan.

--
"We need an energy policy that encourages consumption"
George W. Bush.

"Conservation may be a sign of personal virtue, but it is not a
sufficient basis for a sound, comprehensive energy policy."
Vice President Dick Cheney



C++ question

by Tom Serface » Thu, 23 Mar 2006 11:42:24 GMT

Doesn't make any difference at all if no exceptions are thrown.

Tom







Similar Threads

1. C++ Question: Crashing C++

2. IMapiProp::CopyTo c++ question

What is proper way to use the lppProblems argument the IMapiProp::CopyTo 
method?   Lately, I have been sending in NULL but now would actually like to 
get more verbose information on why the operation is failing.

thanks!



3. managed C++ question - .Net Framework

4. Visual C++ question

Hi All,

I am creating a class library project for VC++ in VS 2005. On
compilation, the following error is returned

error C2664: 'LookupAccountNameW' : cannot convert parameter 1 from
'char *' to 'LPCWSTR'
the line of concern is :

if ( ! LookupAccountName( argv[1], argv[2], userSid, &sidSize, refDom,
&domSize, &sidUse ) )
		err( "LAN()", gle, false );

I think the problem lies in the fact that the .h file has a main
function which is as follows

int main( int argc, char *argv[] )
{
	if ( argc != 3 )
	{
		puts( "Usage: lsa_lear <system name> <account name>" );
		puts( "Enumerates privileges for the named account on the named
machine." );
		puts( "<system name> is the machine where the lookup will
execute." );
		puts( "<account name> is the account to examine, e.g. \"FOO\\felixk
\" or \"Administrators\"." );
		return 1;
	}


	// open the policy object on the target computer

	static SECURITY_QUALITY_OF_SERVICE sqos = { sizeof
SECURITY_QUALITY_OF_SERVICE, SecurityImpersonation,
SECURITY_DYNAMIC_TRACKING, FALSE };
	static LSA_OBJECT_ATTRIBUTES lsaOA = { sizeof LSA_OBJECT_ATTRIBUTES,
NULL, NULL, 0, NULL, &sqos };
	NTSTATUS nts;
	LSA_HANDLE polHandle;
	LsaUnicodeString systemName;

	systemName = argv[1];

	nts = LsaOpenPolicy( systemName, &lsaOA, GENERIC_READ |
GENERIC_EXECUTE, &polHandle );
	err( "LOP()", nts );

	// translate the account name to a RID plus associated domain SID

	SID *userSid;
	char refDom[MAX_PATH];
	SID_NAME_USE sidUse;
	DWORD sidSize, domSize;
	const char *acctTypeString;

	userSid = (SID *) malloc( MAX_PATH );
	sidSize = domSize = MAX_PATH;

	if ( ! LookupAccountName( argv[1], argv[2], userSid, &sidSize,
refDom, &domSize, &sidUse ) )
		err( "LAN()", gle, false );

	acctTypeString = NULL;
	switch ( sidUse )
	{
		case SidTypeAlias:
		case SidTypeUser:
		case SidTypeGroup:
		case SidTypeWellKnownGroup:
			break;
		case SidTypeDomain:
			if ( acctTypeString == NULL )
				acctTypeString = " domain";
			// fall-through
		case SidTypeInvalid:
			if ( acctTypeString == NULL )
				acctTypeString = "n invalid";
			// fall-through
		case SidTypeUnknown:
			if ( acctTypeString == NULL )
				acctTypeString = "n unknown";
			// fall-through
		case SidTypeDeletedAccount:
			if ( acctTypeString == NULL )
				acctTypeString = " deleted";
			printf( "Don't know how to handle a%s account.\n",
acctTypeString );
			return 1;
	}

	LsaUnicodeString *userRights;
	ULONG count;

	userRights = NULL;
	count = 0;
	nts = LsaEnumerateAccountRights( polHandle, userSid,
(LSA_UNICODE_STRING **) &userRights, &count );
	err( "LEAR()", nts );

	DWORD i;
	char *p;

	printf( "%d privileges for user \"%s\" in domain \"%s\":\n", count,
argv[2], refDom );
	for ( i = 0; i < count; ++ i )
	{
		p = (char *) userRights[i]; // must free() later
		printf( "priv %u: %s\n", i, p );
		free( p );
	}

	LsaClose( polHandle );
	free( userSid );

	return 0;
}


Could someone assist me in getting rid of this problem.

Thanks

5. C++ question - CSharp/C#

6. Help - New to Managed C++ Question

Hi

I am an experienced C programmer and we have a large app written in C which 
I have just recompiled with /clr to start to add in managed code to use .NET 
framework and windows forms bit by bit.

I am new to managed C ++(and C++ for that matter).

I am struggling with the fact that it seems you cannot have global managed 
variables although I think I understand why you can't.

i.e. if I declare a managed type or class or object as I would a normal C 
global variable, I get a complier error:

error C3145 cannot declare a global or static managed type object or an _gc 
pointer.

My big problem is I initially want to write some managed C++ 
functions/classes in a new C++ file which I then want to call from my 
existing C code. However these new managed C++ functions need to preserve 
data between themselves and between calls from the C code so it seemed 
global variables where the ideal solution.

So the scenario is something like

C code

call managed C++ function 1 to initialize data

loop
do some processing
call managed C++ function 2 to work with initialized data
end loop

C++ code

function1
creates some managed data (but where does it preserve this if I cant have 
global managed variables)

funtion2
works on previously created managed data

Can anyone advise on how best to tackle this problem.

Thanks

Steve



7. Managed C++ - Question

8. unmanaged & managed C++ questions

1. I want to be use mix unmanaged code with managed code.  In particular, 
the unmanaged code uses MFC CFile to perform file I/O.   Can CFile be used 
in unmanaged code that is mixes with managed code?  I've tried this but 
keep getting a system::exception is thrown with the message "External 
component has thrown an exception" when the CFile instance is created.

2. How does the assignment operator check to see that the source and 
destination objects are not the same in managed code?  For example:

    ref class A
    {
        A% operator=( A %a )
        {
            // if( this != &a )     // this line generates a compiler error.
                {
                ...
                }
        }
    };

The compile generates the error message "error C2446: '!=' : no conversion 
from 'const CManaged' to 'CManaged ^const '" when the line "if( this != 
&a )" is uncommented.  While this is to be expected, what is the proper way 
to check if the source and destination objects are the same?

Ian