|
Hi,
I have a big problem with the following code:
int _tmain(int argc, _TCHAR* argv[])
{
class2 *c2 = new class2();
class1 *c1 = new class1();
c1->doit(c2);
return 0;
}
class2::class2(void)
{
hold = new char*[2];
hold[0] = new char[10];
hold[1] = new char[10];
hold[0] = "test";
hold[1] = "me";
}
void class2::get(int index, char *result)
{
result = hold[index];
return;
}
class1::class1(void)
{
}
void class1::doit(class2 *c2)
{
c2->get(0, pszTmp);
c2->get(1, pszTmp);
return;
}
The Problem is that pszTmp never points to the arrays contents of the array hold.
When I run the code in the debugger it always stays a <bad pointer="">.
Does anyone know what I am making wrong?
P.S.: I am using Visual Studio 2005
|
|
|
|
|
Look at what this is doing:
void class2::get(int index, char *result)
{
result = hold[index];
return;
} You are assigning a new value to the parameter result . Function parameters are passed by value, so the new value is not visible to the caller. Change the parameter to a char*&
|
|
|
|
|
zeus2000 wrote: void class2::get(int index, char *result)
if you want to use result as an OUT (i.e. a return) value then you have to add a level of indirection, making it a pointer:
void class2::get(int index, char * *pResult)
{
*pResult = hold[index];
return;
}
anyway, you don't need this, because you can use the function return value:
char * class2::get(int i)
{
return hold[i];
}
anyway, you don't event need this, because (at least it seems) hold is a global var.
BTW: don't use global vars and always check if index are inside array boundaries, in your code.
Hope that helps
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Thanks for the 'pointers' .
I will try your suggestions.
|
|
|
|
|
On a side note:
hold[0] = new char[10];
hold[0] = "test"; does probably not do what you intend. The allocated array at the first line is lost by the second line assignment (since the variable only holds an address, not a byte sequence)
Either just use the second line, or you'll need to copy the character data to the allocated array using e.g. ::lstrcpy() .
You also might want to consider using const char* instead of just char* when it comes to parameters or function return values for this variable.
|
|
|
|
|
Hi,
I need to make a custom filter that connects to a camera, how does one begin this, and what kind of filter do I have to write?
I am fairly new at Directshow so any help would be greatly appreciated.
|
|
|
|
|
Here's the place to start: Writing DirectShow Filters[^]
The filter type you want is a capture filter. The section of the SDK specifically for that is
Writing Capture Filters[^]
I highly recommend starting with the base classes included with the SDK. It saves alot of work.
There's also working filter samples in the Platform SDK if you want some code to get you started.
The Push Source Filters Sample[^], although not a true capture filter, may be a good place to start.
If you haven't already, download the Platform SDK - all the DirectShow stuff is there
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I have a SDI application in MFC. I split the main frame to 2 rows and 1 columm, then further split first row of the main frame to 1 row and 2 columns statically. the following code is added to OnCreateClient().
// split main frame
m_mainSplitterFrame.CreateStatic(this,2,1);
// further split top main frame to one row and 2 columns
m_childSplitterFrame.CreateStatic(&m_mainSplitterFrame,2,1, WS_CHILD | WS_VISISBLE,m_mainSpitterFrame.IdFromColRow(0,0));
//Create view for sub frame
m_childSplitterFrame.CreateView(0,0,RUNTIME_CLASS(CMyChildView),CSize(100,100),pContext);
m_childSplitterFrame.CreateView(0,1,RUNTIME_CLASS(CMyChildView),CSize(100,100),pContext);
// create bottom view
m_mainSplitterFrame.createView(1,0,RUNTIME_CLASS(CMyMainView),CSize(100,100),pcontext);
retrun TRUE;
After I execute my program, all of my AfxMessageBox used to display in SDI frame now hang my program. Help!!!!!
|
|
|
|
|
That's weird
Tell me something, what you mean with "hang"? Freezing?, or it throws an assertion?.
Because I think it's a little bit strange that issue.
And, since when the program started to "hang"?.
Demian.
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my telephone."
-Bjarne Stroustrup, computer science professor, designer of C++
programming language (1950- )
|
|
|
|
|
Hang to me means the window application never come back and I can not access to any menu in main frame. The progam didn't throw an exception otherwise it should exist program in exception condition. I have to kill the application program through system processes. I am new to MFC. all the help is appreciated. Thanks.
|
|
|
|
|
Ok.
It happen running the programa in a debuging session?.
Why do you think the AfxMessageBox function is the problem?.
Try using the API MessageBox() instead, to see what happen. But I can't see a reason why AfxMessageBox will fail in that way.
And one more. Do you link the program with MFC statically or shared?. (however this configuration it shouldn't "hang" your app., but to try something different).
Demian.
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my telephone."
-Bjarne Stroustrup, computer science professor, designer of C++
programming language (1950- )
|
|
|
|
|
It's strange. Even the standard MFC "About" dialog box hang the program as well. Not just AfxMessageBox. I could conclude that any pop-up messages dialog hang the program. I did try MessageBox(), it still hang the program. I have a test condition if it's failed pop up the message using AfxMessageBox(). If I comment it out the program will not hang. Help!!!!
|
|
|
|
|
Yeah, very strange.
For testing try the following:
Build another SDI aplication and without any extra condition, add an AfxMessageBox() call somewhere, (ie: clicking in the view). If that works, try to think the last thing, (maybe some code), you did in your SDI application, before that strange behaviour.
If the test don't work, so there's something wrong with your MFC libraries or you've change something in the default Visual Studio configuration, (but I don't think so).
The subject of your post says: "AfxMessageBox stop working after split the frame". Well, if really this started to happen since split the FrameWindow, you should come back to that point and see which situations could turn every "modal dialog" to fail and hang the application.
But look at this: (I think this is the real problem).
It looks like your problem is that you "pop" a modal dialog and for some reason you can't see it and consequently you can close that "modal dialog", then it looks like the application is "hang", but it's not, just you can't close the modal dialog because you can't see it or is behind the frame.
Demian.
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my telephone."
-Bjarne Stroustrup, computer science professor, designer of C++
programming language (1950- )
|
|
|
|
|
Thanks for the suggestion. I debug the problem and found that I use InvalidateRect(NULL,FALSE) to redraw the graphic on the right pane in OnDraw(CDC *pDC) of CMyRightPaneView class causing all of my modal dialog to hang mh application. The question is how can I redraw both right and left panes of the splitter pane independently? Help!!!
|
|
|
|
|
I use this code :
hFile = CreateFile(
sFileOrFolderName,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
And i want to get the handle of folder C:\TEST
What must be the parameter sFileOrFolderName ?
Thank you very much.
|
|
|
|
|
Akin Ocal wrote: What must be the parameter sFileOrFolderName ?
_T("C:\\TEST")
You must also specify the FILE_FLAG_BACKUP_SEMANTICS flag in the passed wFlagsAndAttributes (6th)
parameter.
What are you going to do with the handle?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I want to make an enumration with all SIDs or account names in the system.
How can i enumerate permissions by accounts for a specific file/folder ?
I want to make an output like that :
File : c:\a.dat
ACL ACCESS
-----------------------------
user1 read write
user2 read
user3 write
Thank you very much.
|
|
|
|
|
You can use NetUserEnum() and NetQueryDisplayInformation() to enumerate the user accounts, and then use something like the following to check the access rights:
ace_list* m_sAceList = NULL;
BOOL bSuccess = TRUE;
BYTE* pSecDescriptorBuf;
DWORD dwSizeNeeded = 0;
bSuccess = GetFileSecurityW((BSTR)sPath,
DACL_SECURITY_INFORMATION,
NULL,
0,
&dwSizeNeeded);
if (0 == dwSizeNeeded)
{
return failure;
}
pSecDescriptorBuf = new BYTE[dwSizeNeeded];
bSuccess = GetFileSecurityW((BSTR)sPath,
DACL_SECURITY_INFORMATION,
pSecDescriptorBuf,
dwSizeNeeded,
&dwSizeNeeded);
if (!bSuccess)
{
DWORD dwError = GetLastError();
return failure;
}
PACL pacl;
BOOL bDaclPresent, bDaclDefaulted;
bSuccess =
GetSecurityDescriptorDacl((SECURITY_DESCRIPTOR*)pSecDescriptorBuf,
&bDaclPresent, &pacl, &bDaclDefaulted);
if (!bSuccess)
{
DWORD dwError = GetLastError();
dwError << ")\n";
return failure;
}
if (!bDaclPresent)
{
return failure;
}
wchar_t wszAccName[100] = L"";
DWORD accNameSize = sizeof(wszAccName);
PSID ppSid;
DWORD cbSid = 0;
DWORD cchDomainName = 0;
wchar_t * wszDomainName = NULL;
SID_NAME_USE eSidType;
ppSid = (PSID) new BYTE[1024];
cbSid = 1024;
wszDomainName = new wchar_t[1024];
cchDomainName = 1024;
if (!GetUserName( wszAccName, &accNameSize ) ){
}
if (LookupAccountName( NULL,
computer
wszAccName, ppSid,
size needed,
&cbSid,
wszDomainName,
&cchDomainName, &eSidType ))
{
if (IsValidSid(ppSid) == FALSE)
{
gMessageBox("Error: Invalid SID for %s.", wszAccName);
return failure;
} else {
TRUSTEE trustee;
BuildTrusteeWithSid(&trustee, ppSid);
ACCESS_MASK mask = 0;
DWORD dwRetVal = GetEffectiveRightsFromAcl(pacl,
&trustee,
&mask);
if (!(mask & 65536)){
Assert(false);
return failure;
}
are going wrong...
if (mask & FILE_READ_DATA) DebugOut("can read");
if (mask & FILE_WRITE_DATA) DebugOut("can write");
if (mask & FILE_EXECUTE) DebugOut("can exe");
}
} else {
DWORD lErrorCode = GetLastError();
too small.
if (lErrorCode == ERROR_INSUFFICIENT_BUFFER){
}
}
|
|
|
|
|
Thank you very very much...
|
|
|
|
|
How to use map file for finding the crash in DLL?
|
|
|
|
|
There's a good article here.
Whoops, that's a good article but I actually meant this one
I enjoy occasionally wandering around randomly, and often find that when I do so, I get to where I wanted to be [^].
Awasu 2.3 [^]: A free RSS/Atom feed reader with support for Code Project. 50% discount on the paid editions for CP members!
|
|
|
|
|
You don't need to use a map file for this. If you built your DLL with debug information (even the release build naturally) your debugger will take you straight to the point of the crash.
Steve
|
|
|
|
|
I have an application which updates itself every time the taskbar's top-level window changes; how will the application's main window be able to be notified of this?
Thanks for your help!
--PerspX
|
|
|
|
|
WM_ACTIVATEAPP
--
=====
Arman
|
|
|
|
|
For a WM_PAINT message, I am writing some text to the window, ultimately with TextOut(), however, I am not sure how to set a font for the current window DC handle...
Thanks for your help!
--PerspX
|
|
|
|
|