|
|
Hello. My name is Vegas and I am in dire need for help in a college programming class I have called File Structures in C++. I am having alot of trouble with this class and need it to graduate this semester. I was looking for a tutor in the Bay Area in California. I will pay per hour or per session. THanks alot for your time.
please email me at totyt4wrds@yahoo.com
|
|
|
|
|
I have not lived there for years, but if you post a code snippit here and what you do not understand, then someone may explane it to you.
Peaple here will not do your home work for you, but given a piece of code and an explination of what you do not understand, they will usualy give you an answer.
Good luck!
INTP
Every thing is relative...
|
|
|
|
|
I will say right up front that I am very new to C++. What I am trying to do is to take a year that is input and make two new variables out of that year. One variable being the century information and the other variable being the year information. For instance, the year 1999 would produce two variables...one that was equal to 19 and the other would be equal to 99. Any thoughts on how to declare/initiat these two new variables would be greatly appreciated.
|
|
|
|
|
|
Using integers the century is the entered date divided by one hundred, and the year is the entered date minus the century times one hundred. The algorithm is the same no matter what programming language is used.
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
Thanks for the help guys. I guess I got it so stuck in my mind that there was a function to do this that I never stopped long enough to actually think of a mathmatical way to do it.
|
|
|
|
|
Hi! Can anyone tell me what are the advantages in using a .dll instead of a .lib file containing exactly the same functions defintions? For example if I statically link myLib.lib and load-time link myDll.dll (using myDll.lib), they both load when my client executable does... So why is it better to use dlls? Thanks in advance!
|
|
|
|
|
.lib, pros:
* Easier distribution - less files
* Quality ensurance - you get what you've linked
* You can't (easily) intercept function calls between exe and library
* Fast load time - no need for the loader to do extra passes
.lib, cons:
* Exe is bloated
* Not shareable between programs
* Cannot contain resources (I think... :~)
.dll, pros:
* Keeps exe size down
* Easier bug fix management - just fix the dll and replace it
* May be shared between different programs
.dll, cons:
* If several DLLs exist on the system - which one is loaded?
* Easy to intercept by malicious software - it's easy to put a fake layer between exe and dll
* Increases load time for program, as the loader has to do more work
Those are a few points that comes to mind.
|
|
|
|
|
What can I say Sigvardsson is right, but he should have included that you may need to include some DLLs in the install software. Ocassionaly some one asks why their progam works on one machine and not anouther, the answer is usualy because they did not include the required DLL in the install program. If you want your users to be able to just copy the EXE and have it run, then you need to staticaly link the libraries (.libs) with the program. If you know that all the DLLs are standard (on all systems) then you do not need to staticaly link them.
The main advantage of using a DLL is that if there is a problem with it, it is their problem. The main disadvantage of using a DLL is that a problem in an updated version may affect any program depending on it. Of course the same thing applies to ActiveX controls, which are just a specalised version of a DLL.
INTP
Every thing is relative...
|
|
|
|
|
Depending on how they are linked, DLLs can cause problems with such things as memory allocations. When a DLL is linked to CRTL statically, then it will use a different heap than your program. Or if the DLL is linked dynamically to a different version of CRTL then there will be problems.
Also, DLLs actually increase blot for most programs instead of decrease it. When working with LIB files, compiliation modules that are not required will not be linked into the EXE. However, with a DLL, if you EXE only needs a small portion of the code in the DLL, then the DLL version will be larger.
If you aren't having to modify the DLL a lot, using a DLL will improve link times since the code in the DLL won't need to be relinked everytime you rebuild the EXE.
If you have more than one EXE that uses the code, then in the long run, a DLL might reduce the total distribution since since each EXE doesn't contain a copy of the same code.
With many CPP classes, they will fail to operate properly if they are defined in a DLL and used in the EXE. Often the problem is with global variables that aren't properly exported and thus any code in the EXE will access the wrong global variable. With was a problem with the VC6 version of std::map.
There are more issues, but that I what I could think of off the top of my head.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
I have an openGL window within an MFC dialog. I've connected to MSAccess as my DB where i pick coordinates which i use to draw GL_LINES and GL_QUADS.
I've checked out my code and it seems to be working correctly but nothing shows on the GLWindow. Wne i hardcode values ... it shows sometimes and other times it doesn't. Might anyone know what i'm doing wrong here?
Any help would be highly appreciated...
My code for connecting and drawing is as follows:
<br />
<br />
<br />
HRESULT hr;<br />
CoInitialize(NULL);<br />
<br />
try{<br />
hr = cnSURMPtr2.CreateInstance(__uuidof(ADODB::Connection));<br />
if (FAILED(hr))<br />
{<br />
throw _com_error(hr);<br />
}<br />
<br />
hr = rsObjectsPtr.CreateInstance(__uuidof(ADODB::Recordset));<br />
if (FAILED(hr))<br />
{<br />
throw _com_error(hr);<br />
}<br />
<br />
cnSURMPtr2->CursorLocation = ADODB::adUseClient;<br />
<br />
_bstr_t dbLocation(L"");<br />
dbLocation = (L".\\SURM.mdb");<br />
<br />
cnSURMPtr2->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ dbLocation +";Persist Security Info=False","","",ADODB::adConnectUnspecified);<br />
<br />
rsObjectsPtr->Open("SELECT * from Objects", cnSURMPtr2.GetInterfacePtr(),<br />
ADODB::adOpenDynamic, ADODB::adLockOptimistic, ADODB::adCmdText);<br />
<br />
if(!rsObjectsPtr->ADOEOF){<br />
if(rsObjectsPtr->GetRecordCount()>0){<br />
while (rsObjectsPtr->ADOEOF == false){<br />
_variant_t myCoordinates;<br />
<br />
myCoordinates = rsObjectsPtr->GetCollect(L"Coordinates");<br />
<br />
if(myCoordinates.vt != VT_NULL){<br />
CString myStrCoords;<br />
<br />
myStrCoords = static_cast<char *>(_bstr_t(myCoordinates.bstrVal));<br />
<br />
int myArraySize = (myStrCoords.GetLength()/9);<br />
CString *singleCoord = new CString[myArraySize];<br />
int tokenCounter = 0;<br />
<br />
while(myStrCoords.GetLength()>=9){<br />
singleCoord[tokenCounter] = myStrCoords.Left(9);<br />
myStrCoords.Delete(0,10);<br />
tokenCounter++;<br />
}<br />
<br />
if(tokenCounter<=2){<br />
drawLine((string)singleCoord[0],(string)singleCoord[0]);<br />
}<br />
else{<br />
drawQuad((string)singleCoord[0],(string)singleCoord[1],(string)singleCoord[2],(string)singleCoord[3]);<br />
drawQuad("000001000","000001001","000000001","000000000");<br />
}<br />
}
rsObjectsPtr->MoveNext();<br />
}<br />
if(rsObjectsPtr->BOF){<br />
rsObjectsPtr->MoveFirst();<br />
}<br />
if(rsObjectsPtr->ADOEOF){<br />
rsObjectsPtr->MoveLast();<br />
}<br />
};<br />
}<br />
}<br />
catch(_com_error &e)<br />
{<br />
<br />
AfxMessageBox(static_cast<char *>(e.Description()));<br />
}<br />
catch(...)<br />
{<br />
AfxMessageBox("Unhandled Exception");<br />
};<br />
<br />
<br />
drawQuad("000001000","000001001","000000001","000000000");<br />
<br />
SwapBuffers(dc->m_hDC);<br />
}<br />
<br />
This is the code for drawing the QUAD
<br />
void COpenGLControl::drawQuad(string Coord_A, string Coord_B, string Coord_C, string Coord_D){<br />
<br />
<br />
float myAx = atof(Coord_A.substr(0,3).c_str());<br />
float Ax = (myAx/10);<br />
float myAy = atof(Coord_A.substr(3,3).c_str());<br />
float Ay = (myAy/10);<br />
float myAz = atof(Coord_A.substr(6,3).c_str());<br />
float Az = (myAz/10);<br />
<br />
float myBx = atof(Coord_B.substr(0,3).c_str());<br />
float Bx = (myBx/10);<br />
float myBy = atof(Coord_B.substr(3,3).c_str());<br />
float By = (myBy/10);<br />
float myBz = atof(Coord_B.substr(6,3).c_str());<br />
float Bz = (myBz/10);<br />
<br />
float myCx = atof(Coord_C.substr(0,3).c_str());<br />
float Cx = (myCx/10);<br />
float myCy = atof(Coord_C.substr(3,3).c_str());<br />
float Cy = (myCy/10);<br />
float myCz = atof(Coord_C.substr(6,3).c_str());<br />
float Cz = (myCz/10);<br />
<br />
float myDx = atof(Coord_D.substr(0,3).c_str());<br />
float Dx = (myDx/10);<br />
float myDy = atof(Coord_D.substr(3,3).c_str());<br />
float Dy = (myDy/10);<br />
float myDz = atof(Coord_D.substr(6,3).c_str());<br />
float Dz = (myDz/10);<br />
<br />
glBegin(GL_QUADS);<br />
glColor3f(0.0,1.0,0.0);<br />
<br />
glVertex3f(Ax,Ay,Az);<br />
glVertex3f(Bx,By,Bz);<br />
glVertex3f(Cx,Cy,Cz);<br />
glVertex3f(Dx,Dy,Dz);<br />
glEnd();<br />
}<br />
Thanks in advance...
|
|
|
|
|
The only thing I can think of off the top of my head is the default winding in opengl is counter-clockwise, so you need to draw your quad vertexes in that order, unless you change it to clockwise with glFrontFace(GL_CW).
delete this;
* poof! *
|
|
|
|
|
So I want to enumerate the processes using NtQuerySystemInformation() native api.
I load it from ntdll.dll
i use the process structure below unlike the one documented by microsoft. but i've seen that others use it too.
typedef struct _SYSTEM_PROCESS_INFORMATION
{
DWORD dNext;
DWORD dThreadCount;
DWORD dReserved01;
DWORD dReserved02;
DWORD dReserved03;
DWORD dReserved04;
DWORD dReserved05;
DWORD dReserved06;
QWORD qCreateTime;
QWORD qUserTime;
QWORD qKernelTime;
UNICODE_STRING usName;
DWORD BasePriority;
DWORD dUniqueProcessId;
DWORD dInheritedFromUniqueProcessId;
DWORD dHandleCount;
DWORD dReserved07;
DWORD dReserved08;
VM_COUNTERS VmCounters;
DWORD dCommitCharge;
SYSTEM_THREAD Threads[1];
} SYSTEM_PROCESS_INFORMATION;
the thing is that when I call it I don't get any error code or null pointers but the structure's members are zeros.
the dNext member is not zero but I can't obtain the next pointer for another system_process_information because i get the invalid pointer error when I try this:
if (ProcessInfo->dNext!=0)
ProcessInfo=(SYSTEM_PROCESS_INFORMATION_DEF *)((ULONG *)ProcessInfo+ProcessInfo->dNext);
And I have another question.
How much space should I allocate for the ProcessInfo structure
i only allocate for one structure
SYSTEM_PROCESS_INFORMATION *ProcessInfo=(SYSTEM_PROCESS_INFORMATION *)malloc(sizeof(SYSTEM_PROCESS_INFORMATION));
or I shouldn't allocate at all. I will obtain a pointer to the structure anyway ?
here is the code I use:
HMODULE ntHinst;
ntHinst=LoadLibraryA(NTDLL);
if (ntHinst==NULL)
{
MessageBoxA(GetDesktopWindow(),"Error loading ntdll\nThe program will now end","ERROR",MB_ICONSTOP);
return 0;
}
_NtQuerySystemInformation=(NTQUERYSYSTEMINFORMATION)GetProcAddress(ntHinst,"NtQuerySystemInformation");
if(!_NtQuerySystemInformation)
{
MessageBoxA(GetDesktopWindow(),"Error obtaining function pointer\nThe program will now terminate","ERROR",MB_ICONSTOP);
return 0;
}
SYSTEM_PROCESS_INFORMATION *ProcessInfo=(SYSTEM_PROCESS_INFORMATION *)malloc(sizeof(SYSTEM_PROCESS_INFORMATION);
if (IsBadReadPtr(ProcessInfo,sizeof(SYSTEM_PROCESS_INFORMATION))||IsBadWritePtr(ProcessInfo,sizeof(SYSTEM_PROCESS_INFORMATION)))
return 0;
_NtQuerySystemInformation(SystemProcessInformation ,(PVOID)ProcessInfo,sizeof(SYSTEM_PROCESS_INFORMATION),&ret);
if (ret==0)
{
MessageBoxA(GetDesktopWindow(),"Function Call Failed: NtQuerySystemInformation\nThe program will now terminate","ERROR",MB_ICONSTOP);
return 0;
}
if(ProcessInfo==NULL)
{
MessageBoxA(GetDesktopWindow(),"Function Call Failed: NtQuerySystemInformation\nThe program will now terminate","ERROR",MB_ICONSTOP);
return 0;
}
while(ProcessInfo!=NULL)
{
//RtlUnicodeStringToOemString(usname,&ProcessInfo->usName,TRUE);
//MessageBoxA(0,usname->Buffer,"",MB_OK);
//RtlFreeOemString(usname);
HANDLE hProc;
hProc=OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,ProcessInfo->dUniqueProcessId);
if (hProc!=NULL)
{
HMODULE hmods[300];
DWORD retv;
char fname[1024];
EnumProcessModules(hProc,hmods,sizeof(hmods),&retv);
retv=retv/sizeof(DWORD);
GetModuleFileNameA(*hmods,fname,sizeof(fname));
MessageBoxA(GetDesktopWindow(),fname,"Process Name",MB_OK);
}
else if (ProcessInfo->dNext!=0)
ProcessInfo=(SYSTEM_PROCESS_INFORMATION_DEF *)((ULONG *)ProcessInfo+ProcessInfo->dNext);
else
ProcessInfo=NULL;
if (ProcessInfo->dNext!=0)
ProcessInfo=(SYSTEM_PROCESS_INFORMATION_DEF *)((ULONG *)ProcessInfo+ProcessInfo->dNext);
else
ProcessInfo=NULL;
}
free(ProcessInfo);
So I get no errors durin calling. but I also get a structure full of zero's.
What is the pb ?
gabby
|
|
|
|
|
Please,
Can anyone tell me where I can find the resource of the CFileDialog. I don't need the resource found in VC++ samples. I need the original one.
M.N
|
|
|
|
|
"COMMDLG.DLL" contains the resource of CFileDialog and all other common dialogs.
nave
|
|
|
|
|
Thanks nave, but I think that these dialogs are not that used by a program like notepad.
Any way, if there is no other resources, can anybody help me showing the Places Pane when I use a custom CFileDialog template.
M.N
|
|
|
|
|
hello,
i have a class with a bool in it. how can i access the bool (and change its value) from another class? if i try
OtherClass::somebool = false; then i get an error:
error c2597: illegal reference to non-static member 'OtherClass::somebool'
thanks in advance,
sam kline
|
|
|
|
|
Base on the error message, seems like the OtherClass is not instantiated yet.
|
|
|
|
|
|
i did this and it works:
OtherClass SomeClass;
SomeClass.somebool = true;
sam kline
|
|
|
|
|
Ahaa! But do you understatnd why the solution works?
INTP
Every thing is relative...
|
|
|
|
|
hi Sam,
Actually what u r tring first is u r using static member access method for non static member.
Regards,
Divyang Mithaiwala.
|
|
|
|
|
Hello Everyone!! what should i do to generate an opengl terrain in an MFC window. Ive built an opengl window inside my dialog but now i wna display the terrain inside it. Please help!!
Thanks in advance
Aman N
|
|
|
|
|
Hi! I have a problem using a few overloaded functions located in a DLL that I created. The source code for the DLL looks like this:
<br />
#if defined MYDLL_EXPORTS<br />
#define MYDLL_API __declspec( dllexport )<br />
#else<br />
#define MYDLL_API __declspec( dllimport )<br />
#endif<br />
<br />
MYDLL_API __int8 __cdecl readNumber( __int32 &destinationNumber );<br />
MYDLL_API __int8 __cdecl readNumber( double &destinationNumber );
The next lines go in myDll.cpp:
<br />
#include <iostream><br />
#include "myDll.h"<br />
<br />
MYDLL_API __int8 __cdecl readNumber( __int32 &destinationNumber )<br />
{<br />
std::cin >> destinationNumber;<br />
if ( std::cin.bad( ) )<br />
return 0;<br />
<br />
return 1;<br />
}<br />
<br />
MYDLL_API __int8 __cdecl readNumber( double &destinationNumber )<br />
{<br />
std::cin >> destinationNumber;<br />
if ( std::cin.bad( ) )<br />
return 0;<br />
<br />
return 1;<br />
}
It works just fine if I use load-time linking (by linking the myDll.lib too). But what I want to do is use run-time linking, like below:
<br />
#include <windows.h><br />
#include "myDll.h"<br />
<br />
typedef __int8 (__cdecl *ReadInt32NumberFunction( __int32 &destinationNumber );<br />
typedef __int8 (__cdecl *ReadDoubleNumberFunction( double &destinationNumber );<br />
<br />
int main( void )<br />
{<br />
HMODULE moduleHandle;<br />
ReadInt32NumberFunction readInt32Number;<br />
ReadDoubleNumberFunction readDoubleNumber;<br />
__int32 int32Value;<br />
double doubleValue;<br />
<br />
moduleHandle = LoadLibrary( "myDll.dll" );<br />
if ( moduleHandle != NULL )<br />
{<br />
readInt32Number = (ReadInt32NumberFunction)GetProcAddress( moduleHandle, "readNumber" );<br />
readDoubleNumber = (ReadDoubleNumberFunction)GetProcAddress( moduleHandle, "readNumber" );<br />
FreeLibrary( moduleHandle );<br />
}<br />
<br />
return 0;<br />
}
The problem is that both readInt32Number and readDoubleNumber are NULL after calling GetProcAddress. It works if I declare those two functions as extern "C" in myDll.cpp, but then, I cannot use function overloading.
Another problem is that if I want to call readNumber( ) with a __int32 and a double parameter, I must do something like this:
readInt32Number( int32Value );<br />
readDoubleNumber( doubleValue );
I would like to use those two overloaded functions with their own names, like this:
readNumber( int32Value );<br />
readNumber( doubleValue );
Even though all these problems are solved using load-time linking, I DO NOT want to use it. Instead, I would like run-time linking, with LoadLibrary(), GetProcAddress() and FreeLibrary().
Can anyone help me with this, please? Thanks in advance!
|
|
|
|
|