|
Well it's tricky. What you usually do is define a function that creates and returns a pointer to a class and then a function that destroys the object passed. If you don't have the complete class definition, this is as good as you'll get because you will never be able to create an object yourself. How could you without it's definition? The compiler requires this, even pointers to functions imported from DLLs are defined before they are used. Search www.deja.com for "import classes from DLL dynamically" for more information.
|
|
|
|
|
There is even a better way: use COM
But in that case without the source code it's quite tricky. What kind of DLL is it?
Don't try it, just do it!
|
|
|
|
|
Really its tricky, the problem is that the DLL is created with Visual C# 7.0, but I want to import its classes to my project, which is a VC++ 6.0 project, I dont even know if this is possible. (are these two languages compatible?)
Any help will be appreciated.
Regards,
Mohammad
|
|
|
|
|
Hello Everyone,
How to see all items of "tip of the day" at once of VC++? Where do these tips are in hard disk? Thanks.
|
|
|
|
|
If you are talking about VC++ 6.0
Microsoft Visual Studio\Common\MSDev98\Bin\IDE\MSDEV.TIP
Microsoft Visual Studio\Common\MSDev98\Bin\IDE\TOOLS.TIP
Microsoft Visual Studio\Common\MSDev98\Bin\IDE\VCXX.TIP
I haven't seen the tip of the day feature in VStudio.net
Ali
|
|
|
|
|
I am going to create an method to insert Items inside the hash table, However, i don't really know what I should code inside the method.
Should I use push or pop because it is based on a list container for my private attribute.
Here is my code.
hashtable.h
Code:
//HashTable.h
#ifndef HASHTABLE_H
#define HASHTABLE_H
#include <list>using namespace std;
template <typename keytype,="" typename="" valuetype="">
class HashTable
{
public:
void insertItem( const string& key, const VALUETYPE& value );
VALUETYPE getItem( const string& key ) const;
void dump() const;
private:
enum { TABLESIZE = 20 };
struct KeyValuePair {
KEYTYPE key;
VALUETYPE value;
};
list<keyvaluepair> hashTable[ TABLESIZE ];
unsigned getIndex( const char* key ) const; // Hash Function
};
#include "hashtable.tem"
#endif
hashtable.tem
Code:
//hashtable.tem
template <typename keytype,="" typename="" valuetype="">
void HashTable<keytype,valuetype>::insertItem( const string& key, const VALUETYPE& value ) {
}
template <typename keytype,="" typename="" valuetype="">
void HashTable<keytype,valuetype>::dump() const {
for( unsigned iCtr = 0; iCtr < TABLESIZE; iCtr++ ) {
cout << "Bucket #" << iCtr << " contains: ";
list<keyvaluepair>::const_iterator iter;
for( iter = hashTable[ iCtr ].begin(); iter != hashTable[ iCtr ].end(); ++iter ) {
cout << '[' << iter->key.c_str() << ',' << iter->value << ']' << ' ';
}
cout << endl;
}
}
// End of file
Thanks for advice
|
|
|
|
|
hash tables are more like a map, or an array (vector).
Anyway, why aren't you using the stl hash_map class?
AliR
|
|
|
|
|
I am going to write an enumerated type that identifies the suit of the jail cell. However, it should be from another class - Card.
I tried to code it like that
Code:
enum card::suit; //an enumerated type (located in the Card ADT) that identifies the suit of the jail cell
I think it is not going to work, can anyone gives me some suggest?
Here is the code from card.h
Code:
#include <iostream>
using namespace std;
class Card
{
public:
enum Rank
{
ACE,
TWO,
THREE,
FOUR,
FIVE,
SIX,
SEVEN,
EIGHT,
NINE,
TEN,
JACK,
QUEEN,
KING
};
enum Suit
{
SPADES,
HEARTS,
CLUBS,
DIAMONDS
};
Card(); // Default constructor will initialize to Ace of Spades
Card( Rank newRank, Suit newSuit );
Rank getRank() const {return rank;}
Suit getSuit() const {return suit;}
void setRank( Rank newRank );
void setSuit( Suit newSuit );
private:
Rank rank;
Suit suit;
};
ostream& operator<<( ostream& os, const Card& card );
appericate it.
|
|
|
|
|
Since your enum are declared under the public portion of your class you will be able to access it. You should take note that C++ is a case sensitive language. Using your class definition you can use the enum like so:
Card::Suit s;<br />
Card::Rank r;<br />
<br />
r = Card::JACK;<br />
r = Card::HEARTS;
|
|
|
|
|
So you mean in my class
I should code it like that:
private:
stack<card> cards; //an STL stack of Card ADT's
Card::Suit s;
Card::Rank r; //an enumerated type (located in the Card ADT) that identifies the suit of the jail cell
|
|
|
|
|
Yes, if Card::Suit is in another class, if your doing it from the class where Suit and Rank are defined then you can just use Suit and Rank without the Card::, that would be redundant. Your STL stack syntax is wrong, it would be something like std::stack<Card> cards;
|
|
|
|
|
This is what i feel confusing:
I have two private attributes inside the jailCell:
cards - an STL stack of Card ADT’s.
suit – an enumerated type (located in the Card ADT) that identifies the suit of the jail cell.
stack<card> cards; //an STL stack of Card ADT's
but for the enum one, i still don't know how to code it..
|
|
|
|
|
Card::Suit s;
Card::Rank r; //an enumerated type (located in the Card ADT) that identifies the suit of the jail cell
What you had should work. Is it not working? What are you getting?
|
|
|
|
|
<pre>
//It just can't format this correctly.
//My version is 7.1.3088.
//Is this a bug?
// A file download subsystem.
#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <wininet.h>
#include <fstream>
#include <cstdio>
using namespace std;
const int MAX_ERRMSG_SIZE = 80;
const int MAX_FILENAME_SIZE = 512;
const int BUF_SIZE = 1024;
// Exception class for download errors.
class DLExc {
char err[MAX_ERRMSG_SIZE];
public:
DLExc(char *exc) {
if(strlen(exc) < MAX_ERRMSG_SIZE)
strcpy(err, exc);
}
// Return a pointer to the error message.
const char * geterr() {
return err;
}
};
// A class for downloading files from the Internet.
class Download {
static bool ishttp(char *url);
static bool httpverOK(HINTERNET hIurl);
static bool getfname(char *url, char *fname);
static unsigned long openfile(char *url, bool reload,
ofstream &fout);
public:
static bool download(char *url, bool reload=false,
void (*update)(unsigned long, unsigned long)=NULL);
};
// Download a file.
//
// Pass the URL of the file to url.
//
// To reload a file, pass true to reload.
//
// To specify an update function that is called after
// each buffer is read, pass a pointer to that
// function as the third parameter. If no update
// function is desired, then let the third parameter
// default to null.
bool Download::download(char *url, bool reload,
void (*update)(unsigned long, unsigned long)) {
ofstream fout; // output stream
unsigned char buf[BUF_SIZE]; // input buffer
unsigned long numrcved; // number of bytes read
unsigned long filelen; // length of file on disk
HINTERNET hIurl=0, hInet=0; // Internet handles
unsigned long contentlen;// length of content
unsigned long len; // length of contentlen
unsigned long total = 0; // running total of bytes received
char header[80]; // holds Range header
try {
if(!ishttp(url))
throw DLExc("Must be HTTP url.");
// Open the file specified by url.
// The open stream will be returned
// in fout. If reload is true, then
// any preexisting file will be truncated.
// The length of any preexisting file (after
// possible truncation) is returned.
filelen = openfile(url, reload, fout);
// See if Internet connection available.
if(InternetAttemptConnect(0) != ERROR_SUCCESS)
throw DLExc("Can't connect.");
// Open Internet connection.
hInet = InternetOpen("downloader",
INTERNET_OPEN_TYPE_DIRECT,
NULL, NULL, 0);
if(hInet == NULL)
throw DLExc("Can't open connection.");
// Construct header requesting range of data.
sprintf(header, "Range:bytes=%d-", filelen);
// Open the URL and request range.
hIurl = InternetOpenUrl(hInet, url,
header, -1,
INTERNET_FLAG_NO_CACHE_WRITE, 0);
if(hIurl == NULL) throw DLExc("Can't open url.");
// Confirm that HTTP/1.1 or greater is supported.
if(!httpverOK(hIurl))
throw DLExc("HTTP/1.1 not supported.");
// Get content length.
len = sizeof contentlen;
if(!HttpQueryInfo(hIurl,
HTTP_QUERY_CONTENT_LENGTH |
HTTP_QUERY_FLAG_NUMBER,
&contentlen, &len, NULL))
throw DLExc("File or content length not found.");
// If existing file (if any) is not complete,
// then finish downloading.
if(filelen != contentlen && contentlen)
do {
// Read a buffer of info.
if(!InternetReadFile(hIurl, &buf,
BUF_SIZE, &numrcved))
throw DLExc("Error occurred during download.");
// Write buffer to disk.
fout.write((const char *) buf, numrcved);
if(!fout.good())
throw DLExc("Error writing file.");
total += numrcved; // update running total
// Call update function, if specified.
if(update && numrcved > 0)
update(contentlen, total+filelen);
} while(numrcved > 0);
else
if(update)
update(filelen, filelen);
} catch(DLExc) {
fout.close();
InternetCloseHandle(hIurl);
InternetCloseHandle(hInet);
throw; // rethrow the exception for use by caller
}
fout.close();
InternetCloseHandle(hIurl);
InternetCloseHandle(hInet);
return true;
}
// Return true if HTTP version of 1.1 or greater.
bool Download::httpverOK(HINTERNET hIurl) {
char str[80];
unsigned long len = 79;
// Get HTTP version.
if(!HttpQueryInfo(hIurl, HTTP_QUERY_VERSION, &str, &len, NULL))
return false;
// First, check major version number.
char *p = strchr(str, '/');
p++;
if(*p == '0') return false; // can't use HTTP 0.x
// Now, find start of minor HTTP version number.
p = strchr(str, '.');
p++;
// Convert to int.
int minorVerNum = atoi(p);
if(minorVerNum > 0) return true;
return false;
}
// Extract the filename from the URL. Return false if
// the filename cannot be found.
bool Download::getfname(char *url, char *fname) {
// Find last /.
char *p = strrchr(url, '/');
// Copy filename after the last /.
if(p && (strlen(p) < MAX_FILENAME_SIZE)) {
p++;
strcpy(fname, p);
return true;
}
else
return false;
}
// Open the output file, initialize the output
// stream, and return the file's length. If
// reload is true, first truncate any preexisting
// file.
unsigned long Download::openfile(char *url,
bool reload,
ofstream &fout) {
char fname[MAX_FILENAME_SIZE];
if(!getfname(url, fname))
throw DLExc("File name error.");
if(!reload)
fout.open(fname, ios::binary | ios::out |
ios::app | ios::ate);
else
fout.open(fname, ios::binary | ios::out |
ios::trunc);
if(!fout)
throw DLExc("Can't open output file.");
// Get current file length.
return fout.tellp();
}
// Confirm that the URL specifies HTTP.
bool Download::ishttp(char *url) {
char str[5] = "";
// Get first four characters from URL.
strncpy(str, url, 4);
// Convert to lowercase
for(char *p=str; *p; p++) *p = tolower(*p);
return !strcmp("http", str);
}
</pre>
|
|
|
|
|
If you post source code, you need to place it inside <pre> ... </pre> tags. It also helps to check the "Do not treat <'s as HTML tags" box below the message window. This is especially true in your case, since you are asking a question related to source formatting.
Software Zen: delete this;
|
|
|
|
|
Hi,
I have written an ActiveX Object (vc6) and now I wanted to add properties. in the testcontainer it works fine.
now i want to test it in internet explorer and there, i cant set the property anymore via teh <param /> tag, although my control is safe for scripting and initializing.
other question:
how can i intercept <embed "src="asdf.skl" /> within an colecontrol?
thanks in advance
thomas
|
|
|
|
|
May I change tcp header fields or ip header fields, Please help me how I can do that?
For example i want to set syn field in tcp header 1 or 0.
|
|
|
|
|
You can generate own ip packets using raw sockets.
Don't try it, just do it!
|
|
|
|
|
I am trying to run the following file as follows:
the file that I am trying to run takes a switch like this.
msinfo32.exe /nfo outfile.nfo
the line of code I used is;
system("c:\\Program files\\common files\\Microsoft shared\\MSInfo\\msinfo32.exe /nfo outfile.nfo");
compiles but does not runs, I tried to encluse command in double-quots like this
system("\"c:\\Program files\\common files\\Microsoft shared\\MSInfo\\msinfo32.exe /nfo outfile.nfo\"");
error :
'c:\program' not recognized as command...
any ideas?
|
|
|
|
|
Try using ShellExecuteEx.
Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
|
|
|
|
|
Try this:
system("\"c:\\Program files\\common files\\Microsoft shared\\MSInfo\\msinfo32.exe\" /nfo outfile.nfo");
--------^------------------------------------------------------------------------^ In a command line, where the program you're running is in a path with spaces, you need to surround the program with quotes.
Software Zen: delete this;
|
|
|
|
|
Can anyone tell me how to create a link (Hyperlink) to a file from an MFC dialog box? So than when clicking on the link (static text) the file will open.
|
|
|
|
|
|
Hi,
Here is what I am trying to do so far,
I am trying to parse my XML file using the XML parser object pXMLParser to accomplish the following tasks-
pXMLParser->ReplaceNodeVale("input\userinputkey", szUserInput);
pADOObject->GetNextPrompt(pXMLParser->Getxml(), szxml);
pXMLParser->Release();
pXMLParser->Loadxml(szxml);
pXMLParser->GetNodeValue("output\messageid", szNodeVale);
Basically what I am trying to do is, load the xml file, get a particular node value based on the tag value, replace the node value with user input value, parse the xml and then release it. I am using MSXML for this and my XML file looks somewhat like this-
<?xml version="1.0" encoding="utf-8" ?>
- <root>
- <input>
<nodeid>0</nodeid>
<parentid>0</parentid>
<userinputkey>9167791963</userinputkey>
</input>
- <output>
- <vrurequestscript>
- <datainput>
<mainmsgid>100</mainmsgid>
<correctvalues>1,2</correctvalues>
<charset>12</charset>
<length>1</length>
<timeout>10000</timeout>
<timeoutmsgid>200</timeoutmsgid>
<retrycount>3</retrycount>
<retryexitaction>end</retryexitaction>
<retryexitmsgid>300</retryexitmsgid>
</datainput>
- <confirminput>
<mainmsgid>101</mainmsgid>
<correctvalues>1,2</correctvalues>
<charset>12</charset>
<accept>1</accept>
<reject>2</reject>
<length>1</length>
<timeout>10000</timeout>
<timeoutmsgid>200</timeoutmsgid>
<retrycount>3</retrycount>
<retryexitaction>end</retryexitaction>
<retryexitmsgid>300</retryexitmsgid>
</confirminput>
</vrurequestscript>
<nodeid>0</nodeid>
<parentid>0</parentid>
</output>
</root>
If anyone can show me how to go about doing it or point it in the right direction I will really appreciate it.
Thank you
-Ray
|
|
|
|
|
Dear friends,
I developed an ActiveX control using ATL and Visual C++ 7.0. One function exposed by the control takes too many arguments, around 15 in number. As scuh i want to pass structure instead of too many arguments.
But ATL is not giving me any option to add my structure as an argument ot the exposed function ? Please tell me what is the solution of this problem ?
Also i want to use my control by VB/JAvaScript etc. So what is the better way to solve this problem
Imtiaz
|
|
|
|
|