|
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
|
|
|
|
|
What comes in my mind is simply brute force: take a number from list 1 and try every combination in list 2. There are many ways to optimize this because it tries many combinations are surely wrong. for example: sort your list 2 and stop trying combinations if the sum gets bigger then the number from list 1.
If your list 2 numbers have more characteristics (they are not completely random) maybe you can find rules so more needless combinations can be avoided.
I hope this gives you a good start...
Rozis
|
|
|
|
|
Try sorting all #s first. Then for each element in list 1, search for a match in list 2. Upon finding it, remote the item from both lists. So if there are 3 50's in list 1 and 8 50's in list 2, you should be left with 0 in list 1 and 5 in list 2.
Then with your new list 1 and 2, try to reconcile the largest items first. You should do sweeps assuming that an item in list is the sum of two #s. Then after trying this for all items, then look at sums of three #s...
You will loop over the combinations using (d-1) dimensional arrays where d is the # of items in the sum.
Note that this does not guarantee that it will find the right solution.... The correct algorithm is more complex.
You could mark each # as being utilized for sum of k #s in the other list. Then you have to search multiple cases until you find your most explanatory match...
Depending on what other information you have, there may be an even better method.
|
|
|
|
|
Both of replies are very helpful. I think I have got the point. Thank you very very much.
Md. Humayuon Kabir Hemoo
|
|
|
|
|
when i am executing following code:
#include "stdafx.h"
#include "stdio.h"
#include
using namespace std ;
class Derived;
typedef void (Derived::*callbackf)() ;
class Base;
typedef map<base*, callbackf*=""> MYLIST;
class Base
{
public:
Base(void){};
MYLIST mylist;
void Attach(Base* p, callbackf* voidpt){mylist[p] = voidpt;};
~Base(void){};
};
class Derived : public Base
{
public:
void onMoving(){};
Derived(void)
{
callbackf ponMoving = &Derived::onMoving;
Attach(this, &ponMoving);
};
~Derived(void){};
};
int _tmain(int argc, _TCHAR* argv[])
{
Base *b;
b= new Derived();
MYLIST::iterator itr;
itr = b->mylist.begin();
for (itr = b->mylist.begin(); itr != b->mylist.end(); itr++)
{
Base* clsOb = (*itr).first;
callbackf fn = b->mylist[(*itr).first];
(*clsOb.*fn)();
}
return 0;
}
I am getting two errors:
'initializing' : cannot convert from 'void *' to 'callbackf'
'newline' : cannot convert from 'Base *__w64 ' to 'Derived *__w64 '
'.*' : cannot dereference a 'callbackf' on a 'Base'
Can anybody pls help?
modified on Sunday, November 22, 2009 11:38 PM
|
|
|
|
|
Could you please format your code using the "code block" tag (and please, read the posting guidelines at the top of this message board).
|
|
|
|
|
I have tried to compile this code and get 35 errors. I think you need to work on correcting the basics, particularly the typedefs at the beginning.
|
|
|
|
|
I've got DLL which invokes SHGetSpecialFolderPath() function with CSIDL_LOCAL_APPDATA parameter in DLL load handler.
When the DLL is loaded from windows application, ASP.NET application, or windows service and queried that special folder, it returns different locations for that special folder. Moreover in XP and Vista those locations are different.
Is there a way to find out these locations with some specific function when invoked from windows application?
Чесноков
|
|
|
|
|
Correct me if im wrong but SHGetSpecialFolderPath() returns a userrelated folder. The organization of users is different on XP then under Vista. This is the reason you will get different folders. But what is your problem with that?
Rozis
|
|
|
|
|
yes, user related folder, I know it is different.
>>Is there a way to find out these 3 locations with some specific function when invoked from windows application?
Чесноков
|
|
|
|
|
Chesnokov Yuriy wrote: >>Is there a way to find out these 3 locations with some specific function when invoked from windows application?
No function may be available to do this. Because you are trying to access a different user's profile directory, what if the user is an Active Directory user account, and user profile's directory is on a network drive?
What are you trying to implement? there should be some better solution than accessing another user's profile directory.
-Suhredayan
|
|
|
|
|
I need a special folder that already has r/w access for particular user on that computer (either ASP.NET user, service application user, windows application user)
Чесноков
|
|
|
|
|
Chesnokov Yuriy wrote: I need a special folder that already has r/w access for particular user on that computer (either ASP.NET user, service application user, windows application user)
Do you mean a user_profile directory where all the three users have read/write access? if then use: CSIDL_COMMON_APPDATA with SHGetSpecialFolderPath()
-Suhredayan
|
|
|
|