|
It works the same, regardless of g_cpaStrings being global or even if it was cpaStrings as a local, or if it is used locally or passed to a function.
Passing it to a function causes it to decay from array to pointer in either case. But that only changes how the variable appears, not the data behind it.
LPCSTR g_cpaStrings[] = { "One", "Two", "Three", "Four", NULL };
void TestFunc1( LPCTSTR cpaStrings[] )
{
DWORD dwIndex = 0;
while( cpaStrings[ dwIndex ] )
{
TRACE( _T( "String1: %s\n" ), cpaStrings[ dwIndex++ ] );
}
return;
}
void TestFunc2( LPCTSTR *paStrings )
{
DWORD dwIndex = 0;
while( paStrings[ dwIndex ] )
{
TRACE( _T( "String2: %s\n" ), paStrings[ dwIndex++ ] );
}
return;
}
int main( int iArgC, char paArgV[] )
{
LPCSTR cpaStrings[] = { "Five", "Six", "Seven", "Eight", NULL };
DWORD dwIndex = 0;
while( g_cpaStrings[ dwIndex ] )
{
TRACE( _T( "String: %s\n" ), g_cpaStrings[ dwIndex++ ] );
}
dwIndex = 0;
while( cpaStrings[ dwIndex ] )
{
TRACE( _T( "String: %s\n" ), cpaStrings[ dwIndex++ ] );
}
TestFunc1( g_cpaStrings );
TestFunc1( cpaStrings );
TestFunc2( g_cpaStrings );
TestFunc2( cpaStrings );
return( 0 );
} Note that all things being equal, you solution of passing a count of valid data with all pointers is a better solution, and the one I usually suggest first. I am simply offering this solution as an alternative and to better allow the OP to understand how things work.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
hmmm.
i asked because when i first tried your code with a function, i couldn't get it compile (char *[5] vs char*[] errors). but your code compiles fine.
i must've mistyped something somewhere and given up too easily.
|
|
|
|
|
No problem!
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Very clear and good explanation.
Thank you so much.
|
|
|
|
|
Could anyone tell me in FreeRTOS
I have two tasks.
TASK1
TASK2
I want to put TASK1 for sleep of 1000ms and in the sleeping time of TASK1 I want to run TASK2 when the time expired TASK1 again awakeup and so on.
-thx
|
|
|
|
|
ikbahrian wrote: Could anyone tell me in FreeRTOS
You do realize this is a forum for Windows development, don't you? Not that I mind you asking such a question, but just don't be surprised if you fail to get any help.
ikbahrian wrote: I want to put TASK1 for sleep of 1000ms...
Try the Sleep() function.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Sorry David.I was actually stuck with this prb so i post it.
|
|
|
|
|
Well, I don't know anything about FreeRTOS, but many RTOSs have the concept of blue and red threads. Red threads always preempts blue threads and usually you can set the priority between the red threads.
If FreeRTOS has this concept you could schedule TASK2 as a blue thread and TASK1 as a red thread that runs every 1000ms.
Just a shot in the dark, but sometimes something gets hit. :->
--
Roger
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
|
|
|
|
|
I want to put TASK1 for sleep of 1000ms and in the sleeping time of TASK1 I want to run TASK2 when the time expired TASK1 again awakeup and so on.
use WaitForSingleObject with wait time of 1000!, as using it handle you can break it before it completion...
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
I have an OO library that encapsulates the Win32 API. All the files are located in a shared folder for all other projects to use. One of the main files includes another file called "ClassType.h". This file defines a class name for your particular project that the OO library needs. The problem is that the ClassType.h is shared accross all other projects, and every time I build a project I need to edit ClassType.h to include the name of the class for a that particular project.
#ifndef CLASSTYPE_H
#define CLASSTYPE_H
#define ClassType CFoo // this name has to be edited every time I switch projects because the file is shared
#endif // CLASSTYPE_H
ClassType.h is in turn included by a shared file Called CApp.h
#include "ClassType.h"
Is there a way I can make Capp.h dynamically "detect" the current project directory so I can have a different ClassType.h file for every project?
As in:
#include "($Current_project_dir)\Source\ClassType.h" // something like that
|
|
|
|
|
Couldn't you have that define in each projects' stdafx.h?
|
|
|
|
|
I think that using quotes with #include instead of angle brackets causes the same directory and the file #include ing the file to be searched first. So if you just put the localized copy of that file in the same directory as the project-specific source files, it might just work for you.
There is a particular search order that #include uses depending on how the path and/or filename is specified.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
I haven't tried this, by how about...
1) In your project folder, create a file named appname.h, and inside that, put #include "myapp.h"
2) In your shared folder includes, add #include "appname.h"
3) In your project settings "other include directories", make sure you have "." as your first entry, so it would look something like this:
.,../some_folder,../../some_other_folder
If it works, all you have to do is create the file in step one in all your projects...
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi all,
I have Derived a class CMyWnd from CWnd . Now I need to display a web page in
CMyWnd . How it possible?? . I dont want to use CHtmlView.
Thanks
George
|
|
|
|
|
You can host the Internet Explorer control to render your HTML, or use any of the lite HTML controls available (some available from this site, try searching for HTML Control ).
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
See CDHtmlDialog of course it creates a dialogbox if you want to use see an example of it on MSDN with name "MFC Sample DHtmlExplore "
|
|
|
|
|
Try here[^].
Software Zen: delete this;
|
|
|
|
|
Hi,
I've created an MDI application in visual C++ 2005.
It has 2 dialog resources.
1 is the main resource where the user does things and the other I open manually so that when the code for the 1st dialog gets to the part in the code it will show a BMP picture.
I've created a classes for both dialogs.
The second dialog class has a function called showPicture().
<br />
void ImageViewer::showPicture()<br />
{<br />
CPaintDC dc(this);
<br />
HBITMAP bmpHandle = (HBITMAP)LoadImage(NULL,<br />
"cat.bmp",
IMAGE_BITMAP,<br />
0,<br />
0,<br />
LR_LOADFROMFILE|LR_CREATEDIBSECTION|LR_DEFAULTSIZE);<br />
CBitmap bmpPicture;<br />
CDC mdcPicture;<br />
CBitmap *bmpFromHandle = bmpPicture.FromHandle(bmpHandle);<br />
<br />
CRect rctPicture;<br />
m_nCam1img.GetWindowRect(&rctPicture);<br />
<br />
mdcPicture.CreateCompatibleDC(&dc);<br />
CBitmap * bmpPrevious = mdcPicture.SelectObject(bmpFromHandle);<br />
ScreenToClient(&rctPicture);<br />
<br />
dc.BitBlt(rctPicture.left, rctPicture.top,<br />
rctPicture.Width(), rctPicture.Height(),<br />
&mdcPicture, 0, 0, SRCCOPY);<br />
<br />
DeleteObject(bmpHandle);<br />
<br />
}<br />
I call this function in the 1st dialog's class.
The program compiles but when I run it and the program gets to the call for the showPicture() function and comes to this line:
<br />
CPaintDC dc(this);
it crashes and gives this error:
Debug Assertion Failed!
Program: c:\..\test.exe
File: f:\..\ship\atlmfc\src\mfc\wingdi.cpp
Line: 1090
Press retry to debug application
When I press re-try it goes to this code:
<br />
ASSERT(::IsWindow(pWnd->m_hWnd));<br />
in wingdi.cpp
<br />
CPaintDC::CPaintDC(CWnd* pWnd)<br />
{<br />
ASSERT_VALID(pWnd);<br />
ASSERT(::IsWindow(pWnd->m_hWnd));<br />
<br />
if (!Attach(::BeginPaint(m_hWnd = pWnd->m_hWnd, &m_ps)))<br />
AfxThrowResourceException();<br />
}<br />
what am i doing wrong?
the showPicture() function works fine if i create a single dialog based application....
how can I load/view a bitmap in an MDI application environment?
thanks,
Kitty5
|
|
|
|
|
Sounds to me like your showPicture() function is being called before the window has completed its initalization and has been fully created.
The code at the start of showPicture() should either check for a valid m_hWnd , or the code calling it should check for it before calling that function.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
James,
the following is my imageViewer class:
<br />
IMPLEMENT_DYNAMIC(ImageViewer, CDialog)<br />
<br />
ImageViewer::ImageViewer(CWnd* pParent )<br />
: CDialog(ImageViewer::IDD, pParent)<br />
{<br />
}<br />
<br />
ImageViewer::~ImageViewer()<br />
{<br />
}<br />
<br />
void ImageViewer::DoDataExchange(CDataExchange* pDX)<br />
{<br />
CDialog::DoDataExchange(pDX);<br />
DDX_Control(pDX, IDC_CAM1_IMG, m_nCam1img);<br />
DDX_Control(pDX, IDOK, m_ok);<br />
DDX_Control(pDX, IDCANCEL, m_canc);<br />
}<br />
<br />
<br />
BEGIN_MESSAGE_MAP(ImageViewer, CDialog)<br />
END_MESSAGE_MAP()<br />
<br />
BOOL ImageViewer::OnInitDialog() <br />
{<br />
CDialog::OnInitDialog();<br />
<br />
return TRUE;
}<br />
<br />
void ImageViewer::showPicture()<br />
{<br />
CPaintDC dc(this);
<br />
HBITMAP bmpHandle = (HBITMAP)LoadImage(NULL,<br />
"cat.bmp",
IMAGE_BITMAP,<br />
0,<br />
0,<br />
LR_LOADFROMFILE|LR_CREATEDIBSECTION|LR_DEFAULTSIZE);<br />
CBitmap bmpPicture;<br />
CDC mdcPicture;<br />
CBitmap *bmpFromHandle = bmpPicture.FromHandle(bmpHandle);<br />
<br />
CRect rctPicture;<br />
m_nCam1img.GetWindowRect(&rctPicture);<br />
<br />
mdcPicture.CreateCompatibleDC(&dc);<br />
CBitmap * bmpPrevious = mdcPicture.SelectObject(bmpFromHandle);<br />
ScreenToClient(&rctPicture);<br />
<br />
dc.BitBlt(rctPicture.left, rctPicture.top,<br />
rctPicture.Width(), rctPicture.Height(),<br />
&mdcPicture, 0, 0, SRCCOPY);<br />
<br />
DeleteObject(bmpHandle);<br />
<br />
}<br />
it doesn't have much.
i open the dialog for this class before i call the showPicture() i also have break points right now... so any initialization should be complete by then... or am i just confused?
thanks,
Kitty5
|
|
|
|
|
If this is a modal dialog, you will not have a way to externally call the showPicture() function while the dialog's window is valid.
For example:
ImageViewer dlgIM;
dlg.DoModal();
dlg.showPicture(); That only works if you are calling showPicture() from within the dialog's code somewhere either directly from OnInitDialog() or triggered by some kind of event.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
James,
I set up the dialogs to be modeless.
it's created:
<br />
void CCameraDataGenTxApp::OnImageViewer()<br />
{<br />
ImageViewer *imgViewDlg;<br />
imgViewDlg = new ImageViewer();<br />
imgViewDlg->Create(IDD_IMAGEVIEWER, NULL);<br />
imgViewDlg->SetWindowPos(NULL, 0, 0, 620, 390, SWP_NOMOVE);<br />
imgViewDlg->ShowWindow(SW_SHOW);<br />
}<br />
Called:
<br />
BEGIN_MESSAGE_MAP(CCameraDataGenTxApp, CWinApp)<br />
ON_COMMAND(ID_APP_ABOUT, &CCameraDataGenTxApp::OnAppAbout)<br />
ON_COMMAND(ID_FILE_NEW, &CWinApp::OnFileNew)<br />
ON_COMMAND(ID_CAMERA, &CCameraDataGenTxApp::OnCamera1Tx)<br />
ON_COMMAND(ID_IMGVIEWER, &CCameraDataGenTxApp::OnImageViewer)<br />
ON_COMMAND(ID_FILE_OPEN, &CWinApp::OnFileOpen)<br />
END_MESSAGE_MAP()<br />
that's why i thought that this would work.
what i'm trying to achieve at the end is to have 3 separate window where we can view pictures from 3 separate cameras we collect data from and 1 dialog box that controls the camera....
if I had just a dialog based app my code works. i simply initialize everything in ::OnInitDialog() and then it has a function called ::OnPaint() that I can call showImage()....
It is in an MDI application where everything gets hazy...
since it doesn't have an ::OnPaint() or ::OnInitDialog() function.
Please advice.
thanks,
Kathleen
Kitty5
|
|
|
|
|
When you trace your code line to line did you see a null value of variables
|
|
|
|
|
WhiteSky,
no i do not see a null value of variable because when i come into the showPicture() function the very 1st thing crashes... CPaintDC dc(this);
which gives me an error:
<br />
it crashes and gives this error:<br />
Debug Assertion Failed!<br />
Program: c:\..\test.exe<br />
File: f:\..\ship\atlmfc\src\mfc\wingdi.cpp<br />
Line: 1090<br />
<br />
Press retry to debug application<br />
<br />
When I press re-try it goes to this code:<br />
<br />
ASSERT(::IsWindow(pWnd->m_hWnd));<br />
in wingdi.cpp
<br />
CPaintDC::CPaintDC(CWnd* pWnd)<br />
{<br />
ASSERT_VALID(pWnd);<br />
ASSERT(::IsWindow(pWnd->m_hWnd));<br />
<br />
if (!Attach(::BeginPaint(m_hWnd = pWnd->m_hWnd, &m_ps)))<br />
AfxThrowResourceException();<br />
}<br />
my reply to James' post:
my dialogs are modeless...
that's why i thought that this would work.
what i'm trying to achieve at the end is to have 3 separate window where we can view pictures from 3 separate cameras we collect data from and 1 dialog box that controls the camera....
if I had just a dialog based app my code works. i simply initialize everything in ::OnInitDialog() and then it has a function called ::OnPaint() that I can call showImage()....
It is in an MDI application where everything gets hazy...
since it doesn't have an ::OnPaint() or ::OnInitDialog() function.
Please advice.
thanks,
Kitty
Kitty5
|
|
|
|
|
I need to knwo how to compare to bitmaps so as to detect motion. The bitmaps come from a webcam stream and i have managed to grab the frames as needed. I just now need help in comparing these frames for motion.
|
|
|
|
|