|
I have edited my previous post, since code demonstrating new usage was the same (copying I guess).
I do not know if what tool you are using to write your programs. If MSVC and you are using multithreaded runtime libraries, using new is thread safe.
I do not know what function you are using to create thread. Nevertheless if you are concern about memory allocation, allocate your structure in a main thread and pass it as a parameter to a worker thread. After thread terminates, delete object.
I think using new to allocate object is much safer than using other allocation calls.
If you are serious about Windows programming I would suggest writing small Win32 application and see what window procedure does. There is nothing to be confused about windows messages, once you grasp the idea of message loop, dispatching and handling messages. Borland doe not shield you from Windows messages.
I would stay with MS tools and after familiarizing with Windows insides I would suggest using MFC. You can use other higher level languages and packages but they are using separate framework to allow application to run on Windows and make Windows insides transparent to a programmer.
JohnCz
MS C++ MVP
|
|
|
|
|
It was really wierd that new operator's proformance is much lower than HeapAlloc when more than ten threads are allocating memory form different heaps. Maybe new operator is using a mutex lock to prevent allocation errors in MSVC. The "heap concept" is hidden in new operator and I cannot free a memory from another thread, the DbgMsg shows that the "delete" operator can only free a memory from a thread's "local" heap. But HeapAlloc(Win API) allow choosing which heap to manipulate, so I eventually chose HeapAlloc.
Although I like it better when Message Dispatching and handling is hidden to programmer(I don't need to care about the details, source code is hidden, C++ CLR also have this "hallmark"), but message is the basis of window programming after all. I need to know the basic thing(maybe this is why the 'F' in "MFC" is "foundation").
I've really learned a lot, Thanks again!
|
|
|
|
|
You are welcome.
Treat messages like codes. Windows OS or other windows send messages to inform what is going on and may interest window. Like WM_MOUSEMOVE means mouse is mowing over you window and cursor position id 20, 340.
User selected item in a drop box: Hey, parent selection changed!
Messages are delivered to a thread message queue (LILO) by PostMessage and dispatched from message loop in WinMain.
Others are delivered by directly calling window procedure (Send message).
Some of them carry additional information as parameters some do not.
In VS create basic Win32 application with “Hello world” option and everything will be clear.
If you have any questions regarding API based application, post it here.
Once you understand at list basics you can switch to MFC. Remember MFC does not wrap all Windows API calls therefore knowing Windows will help.
Good Luck.
JohnCz
MS C++ MVP
|
|
|
|
|
hi,i would like to ask.. if the running time of java programs was more difficult to analyze,than c programs????
|
|
|
|
|
Assuming that both Java and C have functions to capture the time then there should be no difference. Maybe you should try it first.
|
|
|
|
|
yah, maybe i should have to!!!
running time includes fetching and storing..right?
|
|
|
|
|
It depends what you mean by 'running' time. In a multi-application OS like Windows the running time (i.e. wall clock time) depends on what else is running in the machine. If you are talking of consumed CPU cycles then that will largely depend on the data that is processed. You would expect C programs to be a little faster than Java owing to the difference in object code, but that is not always the case.
|
|
|
|
|
ahhh i see!!!
thank you by the way sir!!!
|
|
|
|
|
I do call ITextServices::Release() to release that reference. But the allocated memory isn't released. I got following stack trace by "!heap -p -a" in Windbg after ITextServices::Release() is called.
Or, who can tell me what is the offical steps to release ITextServices correctly?
Anybody could help me? Thanks in advance.
0:001> !heap -p -a 027b5360
address 027b5360 found in
_HEAP @ 150000
HEAP_ENTRY Size Prev Flags UserPtr UserSize - state
027b5360 0013 0000 [07] 027b5368 00080 - (busy)
Trace: 02fb
7c98ee72 ntdll!RtlDebugAllocateHeap+0x000000e1
7c96b3a2 ntdll!RtlAllocateHeapSlowly+0x00000044
7c93aa2b ntdll!RtlAllocateHeap+0x00000e64
7c8099ef kernel32!LocalAlloc+0x00000058
74de8f78 RICHED20!CW32System::PvReAlloc+0x00000026
74d9577c RICHED20!CArrayBase::ArAdd+0x00000040
74d957d1 RICHED20!CArrayBase::ArInsert+0x0000001a
74da426c RICHED20!CTxtArray::AddBlock+0x0000001c
74dd90d6 RICHED20!CTxtPtr::InsertRange+0x00000034
74dd99bf RICHED20!CTxtPtr::ReplaceRange+0x00000110
74dcb3a6 RICHED20!CRchTxtPtr::ReplaceRange+0x0000039c
74da7b24 RICHED20!CTxtEdit::SetRichDocEndEOP+0x00000041
74daa42f RICHED20!CTxtEdit::Init+0x000003be
74ddd88a RICHED20!CreateTextServices+0x000000a0
*** WARNING: Unable to verify checksum for d:\Build\BooguNT\BooguNote_2009_11_22_datime\BooguNote\Debug\BooguNote.exe
4b7b40 BooguNote!CBooguNoteText::Init+0x00000260
4bd4ad BooguNote!CreateHost+0x000000fd
4bd5f2 BooguNote!CreateTextControl+0x00000062
4cb745 BooguNote!CBooguNoteView::CreateTextBlock+0x00000085
4bf801 BooguNote!CBooguNoteView::LoadData+0x00000141
4bea3b BooguNote!CBooguNoteView::OpenFile+0x0000002b
4beb5e BooguNote!CBooguNoteView::OnCreate+0x0000008e
4e7790 BooguNote!CBooguNoteView::ProcessWindowMessage+0x000000a0
4a786a BooguNote!ATL::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<1442840576,0> >::WindowProc+0x0000007a
77d18734 USER32!InternalCallWinProc+0x00000028
77d18816 USER32!UserCallWinProcCheckWow+0x00000150
77d1b4c0 USER32!DispatchClientMessage+0x000000a3
77d1f9fe USER32!__fnINLPCREATESTRUCT+0x0000008b
7c92e473 ntdll!KiUserCallbackDispatcher+0x00000013
77d1fecc USER32!_CreateWindowEx+0x000001ed
77d1fc58 USER32!CreateWindowExW+0x00000033
4aa5f2 BooguNote!ATL::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<1442840576,0> >::Create+0x00000122
4f0e29 BooguNote!ATL::CWindowImpl<CBooguNoteView,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::Create+0x000000a9
:001> !heap -p -a 027b53f8
address 027b53f8 found in
_HEAP @ 150000
HEAP_ENTRY Size Prev Flags UserPtr UserSize - state
027b53f8 0008 0000 [07] 027b5400 00028 - (busy)
Trace: 02fe
7c98ee72 ntdll!RtlDebugAllocateHeap+0x000000e1
7c96b3a2 ntdll!RtlAllocateHeapSlowly+0x00000044
7c93aa2b ntdll!RtlAllocateHeap+0x00000e64
7c8099ef kernel32!LocalAlloc+0x00000058
74d919fb RICHED20!CW32System::PvAlloc+0x00000011
74d919e3 RICHED20!operator new+0x0000000f
74dde615 RICHED20!CTxtEdit::GetDocInfo+0x00000013
74ddd7e1 RICHED20!CTxtEdit::TxSetText+0x0000001b
4b7bc5 BooguNote!CBooguNoteText::Init+0x000002e5
4bd4ad BooguNote!CreateHost+0x000000fd
4bd5f2 BooguNote!CreateTextControl+0x00000062
4cb745 BooguNote!CBooguNoteView::CreateTextBlock+0x00000085
4bf801 BooguNote!CBooguNoteView::LoadData+0x00000141
4bea3b BooguNote!CBooguNoteView::OpenFile+0x0000002b
4beb5e BooguNote!CBooguNoteView::OnCreate+0x0000008e
4e7790 BooguNote!CBooguNoteView::ProcessWindowMessage+0x000000a0
4a786a BooguNote!ATL::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<1442840576,0> >::WindowProc+0x0000007a
77d18734 USER32!InternalCallWinProc+0x00000028
77d18816 USER32!UserCallWinProcCheckWow+0x00000150
77d1b4c0 USER32!DispatchClientMessage+0x000000a3
77d1f9fe USER32!__fnINLPCREATESTRUCT+0x0000008b
7c92e473 ntdll!KiUserCallbackDispatcher+0x00000013
77d1fecc USER32!_CreateWindowEx+0x000001ed
77d1fc58 USER32!CreateWindowExW+0x00000033
4aa5f2 BooguNote!ATL::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<1442840576,0> >::Create+0x00000122
4f0e29 BooguNote!ATL::CWindowImpl<CBooguNoteView,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::Create+0x000000a9
4ef8d8 BooguNote!CMainFrame::OpenFileByName+0x00000158
4e900c BooguNote!CMainFrame::OnDropFiles+0x0000013c
4e10b7 BooguNote!CMainFrame::ProcessWindowMessage+0x000003a7
5166ca BooguNote!ATL::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<114229248,262400> >::WindowProc+0x0000007a
77d18734 USER32!InternalCallWinProc+0x00000028
77d18816 USER32!UserCallWinProcCheckWow+0x00000150
0:001> !heap -p -a 027b5438
address 027b5438 found in
_HEAP @ 150000
HEAP_ENTRY Size Prev Flags UserPtr UserSize - state
027b5438 001b 0000 [07] 027b5440 000c0 - (busy)
Trace: 02ff
7c98ee72 ntdll!RtlDebugAllocateHeap+0x000000e1
7c96b3a2 ntdll!RtlAllocateHeapSlowly+0x00000044
7c93aa2b ntdll!RtlAllocateHeap+0x00000e64
7c8099ef kernel32!LocalAlloc+0x00000058
74de8f78 RICHED20!CW32System::PvReAlloc+0x00000026
74d9577c RICHED20!CArrayBase::ArAdd+0x00000040
74da202d RICHED20!CDisplayML::RecalcLines+0x000000a3
74da2ba2 RICHED20!CDisplayML::RecalcView+0x00000033
74d9ee4e RICHED20!CDisplay::RecalcView+0x00000029
74ddb211 RICHED20!CTxtEdit::OnTxInPlaceActivate+0x00000066
4b7c7c BooguNote!CBooguNoteText::Init+0x0000039c
4bd4ad BooguNote!CreateHost+0x000000fd
4bd5f2 BooguNote!CreateTextControl+0x00000062
4cb745 BooguNote!CBooguNoteView::CreateTextBlock+0x00000085
4bf801 BooguNote!CBooguNoteView::LoadData+0x00000141
4bea3b BooguNote!CBooguNoteView::OpenFile+0x0000002b
4beb5e BooguNote!CBooguNoteView::OnCreate+0x0000008e
4e7790 BooguNote!CBooguNoteView::ProcessWindowMessage+0x000000a0
4a786a BooguNote!ATL::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<1442840576,0> >::WindowProc+0x0000007a
77d18734 USER32!InternalCallWinProc+0x00000028
77d18816 USER32!UserCallWinProcCheckWow+0x00000150
77d1b4c0 USER32!DispatchClientMessage+0x000000a3
77d1f9fe USER32!__fnINLPCREATESTRUCT+0x0000008b
7c92e473 ntdll!KiUserCallbackDispatcher+0x00000013
77d1fecc USER32!_CreateWindowEx+0x000001ed
77d1fc58 USER32!CreateWindowExW+0x00000033
4aa5f2 BooguNote!ATL::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<1442840576,0> >::Create+0x00000122
4f0e29 BooguNote!ATL::CWindowImpl<CBooguNoteView,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::Create+0x000000a9
4ef8d8 BooguNote!CMainFrame::OpenFileByName+0x00000158
4e900c BooguNote!CMainFrame::OnDropFiles+0x0000013c
4e10b7 BooguNote!CMainFrame::ProcessWindowMessage+0x000003a7
5166ca BooguNote!ATL::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<114229248,262400> >::WindowProc+0x0000007a
|
|
|
|
|
Hi.
First I would like to say that I am quite the beginner using C++. I have just started to learn DirectX and I have a problem compiling. Maybe this post should be put in the Graphics forum but I don’t know if it is really a Graphics problem.
I went through the tutorial called “Beginning Direct3D by Vahid Kazemi” found here codeproject.com[^] and it worked great. I am currenly reading a book called “Introduction to 3D game programming with DirectX 9.0 by Frank D. Luna”. In the beginning of this book there is a tutorial/sample project that basically is the same as the one by Vahid Kazemi only structured a bit differently. It has the basic framework that I am supposed to build the rest of the tutorials in the book on. Now I am having some problems getting the project form the book to compile.
Here is the compiler error:
-----
1>Linking...
1>Main.obj : error LNK2019: unresolved external symbol "bool __cdecl d3d::InitD3D(struct HINSTANCE__ *,int,int,bool,enum _D3DDEVTYPE,struct IDirect3DDevice9 * *)" (?InitD3D@d3d@@YA_NPAUHINSTANCE__@@HH_NW4_D3DDEVTYPE@@PAPAUIDirect3DDevice9@@@Z) referenced in function _WinMain@16
1>C:\Users\Stian H. Haug\Documents\Visual Studio 2008\Projects\Spill Programmering\Spillprogrammering - Sample One\Debug\Spillprogrammering - Sample One.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\Users\Stian H. Haug\Documents\Visual Studio 2008\Projects\Spill Programmering\Spillprogrammering - Sample One\Spillprogrammering - Sample One\Debug\BuildLog.htm"
1>Spillprogrammering - Sample One - 2 error(s), 0 warning(s)
-----
Judgeing by the error i thought it might be a linking error. However I managed to compile the tutorial by Vahid Kazemi and I have included all the same files, .lib and such that I included in that tutorial.
Here is my WinMain loop where I call the InitD3D() function.
int WINAPI WinMain(HINSTANCE hinstance,
HINSTANCE prevInstance,
PSTR cmdLine,
int showCmd)
{
if(!d3d::InitD3D(hinstance, 800, 600, true, D3DDEVTYPE_HAL, &Device))
{
::MessageBox(0, "InitD3D() - FAILED", 0, 0);
return 0;
}
if(!Setup())
{
::MessageBox(0, "Setup() - FAILED", 0, 0);
return 0;
}
d3d::EnterMsgLoop( Display );
Cleanup();
Device->Release();
return 0;
}
Here is the prototype in my header file:
bool InitD3D(
HINSTANCE hInstance,
int width, int height,
bool windowed,
D3DDEVTYPE deviceType,
IDirect3DDevice9** device);
I belive the InitD3D()function is implemented in one of these files:
#include <d3d9.h>
#include <d3dx9.h>
I have included them both.
If anyone can help me with understanding this problem it would be great. If you want me to post the whole code i can.
Thanks!
modified on Sunday, November 22, 2009 3:38 PM
|
|
|
|
|
stianhh wrote: I belive the InitD3D()function is implemented in one of these files:
You need to verify which it is! From the error messages you have posted there is no implementation of d3d::InitD3D() , so you need to find out if it is implemented in one of your source files, or is part of a library/dll that should be available to the linker. The article you refer to shows a local implementation of this function.
|
|
|
|
|
Seems the example in the book mentioned a .cpp file implementing the InitD3D() function that had to be downloaded from the books homepage. Sorry but the way it was written in the book didn't make me think twice about weather the function was implemented in the included files or not.
Thanks for the help!
|
|
|
|
|
Generally speaking the .h files should only contain declarations. All the implementation code should be in the .cpp files.
And yes, I do know that ATL does it the other way, but that is a foul abomination that should be wiped from the face of the earth.
|
|
|
|
|
stianhh wrote: I have just started to learn DirectX and I have a problem compiling.
It's not really at compilation but rather at linking.
You probably forgot to link to the direct3D library. Did you follow these steps described at the begining of the article ?
If you use Microsoft Visual C++ create an empty Win32 project and in the Project Properties>Linker>Input>Additional Dependencies add d3d8.lib (main direct3d library), d3dx8.lib (extensions to the main library) and winmm.lib (windows multimedia library).
|
|
|
|
|
Hi,
I need to search for a file in a specific directory. This directory would also have subdirectories in it. Can I have a API / code snippet for this.
Thanks in advance.
|
|
|
|
|
There is no single API to do that, however this[^] MSDN sample may help.
-Suhredayan
|
|
|
|
|
FindFirstFile、FindNextFile
|
|
|
|
|
In addition to FindFirstFile, you could use FileExists to search each directory for a match. If you intend to search subdirectories, you still need to to identify them.
#include <sys stat.h=""> //for FileExists
bool FileExists(char * const strFilename) {
struct stat stFileInfo;
bool blnReturn;
int intStat;
// Attempt to get the file attributes
intStat = stat(strFilename,&stFileInfo);
if(intStat == 0) {
// We were able to get the file attributes
// so the file obviously exists.
blnReturn = true;
}
else {
// We were not able to get the file attributes.
// This may mean that we don't have permission to
// access the folder which contains this file. If you
// need to do that level of checking, lookup the
// return values of stat which will give you
// more details on why stat failed.
blnReturn = false;
}
return(blnReturn);
}
|
|
|
|
|
I wrote a program in C++ to store student details. Basically it stores 5 student's registration numbers with their GPAs and there are other functions in the program too.
I'm trying to convert the code to work in 'C' but I'm getting too many errors, especially where the arrays are concerned.
It would be very helpful if anyone could point me in the right direction or even give me a piece of the converted "C" code because that way I'll know what to change as I know C++ but I don't know C.
A piece of my C++ code i.e. the case1 statement is as follows:
#include*stdio.h
#include*stdlib.h
int main()
{
const int size = 5;
float gpa[size],sum=0,avg;
int i,regno[size],reg,flag=0;
char value;
while(value!='0')
{//start of while
cout<<"\t\t\t---MAIN MENU---\n\n\n\n";
cout<<"\n\nPress 1 to enter GPA(s) and registration number(s)";
cout<<"\n\nPress 2 to upgrade GPA(s)";
cout<<"\n\nPress 3 to display average of all the entered GPAs";
cout<<"\n\nPress 4 to display all the GPAs and regestration numbers";
cout<<"\n\nPress 5 to display registration number(s) of GPA of 4 holders";
cout<<"\n\nPress 0 to exit the program";
cout<<"\n\n\n\n\nEnter value = ";
cin>>value;
if(value=='0')
{
break;
}
switch(value)
{
case '1':
for(i=0;i*is less than*size;i++)
{
cout<<"\t\t\tENTER DATA\n\n\n\n";
cout<<"\n\n\nEnter GPA of student: "<<i+1<<" :="" ";
="" cin="">>gpa[i];
cout<<"\n\n\nEnter registration number of student: "<<i+1<<" :="" ";
="" cin="">>regno[i];
}
cout<<"\n\n\n\t\tPress any key to go back to the main menu";
getch();
break;
}
}
modified on Sunday, November 22, 2009 12:11 AM
|
|
|
|
|
You aren't using any of the C++ language features as such. Simply use printf instead of cout and scanf instead of cin . Search for examples on usage of these functions. They're not very difficult anyway.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
hivicky wrote: I know C++ but I don't know C.
I think you may be slightly confused; apart from cin and cout your code is C not C++.
|
|
|
|
|
"C" language do not support stream read and write(cin/cout), you can use "printf" & "scanf".
Example:
C++
cout<<"\t\t\tENTER DATA\n\n\n\n";
C
printf("\t\t\tENTER DATA\n\n\n\n");
|
|
|
|
|
Hello, i have a main dialog that calls to a modal dialog , and i want to initialize the controls (their variables associated) but in this modal dialog there isn't a OnInitDialog like in the main dialog , why? so how can i do initialize the controls? .thanks.
|
|
|
|
|
Oh, i found the solution, so easy, i'm newbie!
|
|
|
|
|
Hi,
I'm developing a reconciliation software. I have to find the matching items using some rules. However, some items represent sum of other items but I don't know which are they. So, I need to find, by trial and error, the numbers that represent the another number.
List 1 : 10, 300, 50
List 2 : 5, 50,20,25,150,5,30,50,5,20
Here 10 = 5 + 5
300 = 50 + 150 + 25 + 5 + 50 + 20
50 = 20 + 30
There may be hundreds of such number like in List 2 and dozens likes List 1. My job is to find which number make up the numbers in List 1 base only on the numbers. Can any one knows about any algorithm to achieve this task.
Thanks
Md. Humayuon Kabir Hemoo
|
|
|
|
|