|
This would be a really bad idea since it would be totally confusing to anyone reading your code!
Why don't you do it like this:
typedef struct tagInputfields
{
UINT nMask ;
CString fields[5] ;
} ;
CString val = m_ifFields.fields[1] ;
Lets be honest, isn't it amazing how many truly stupid people you meet during the course of the day. Carry around a pad and pencil, you'll have twenty or thirty names by the end of the day - George Carlin
Awasu 2.0 [^]: A free RSS reader with support for Code Project.
|
|
|
|
|
I dont know wheather [] operator can be overloaded in struture, but you can always use class and over load it, it wont make any change in the usage.
MSN Messenger.
prakashnadar@msn.com
Tip of the day of visual C++ IDE.
"We use it before you do! Visual C++ was developed using Visual C++"
|
|
|
|
|
Hi Prakash, in C++, a struct is the same as a class except that all the members of a struct are public by default.
class AA
{
public:
AA() { }
};
struct BB
{
BB() { }
};
Maxwell Chen
|
|
|
|
|
First you have to decide whether you want the result of operator[] to be an lvalue (meaning, you can assign to the result). Let's assume no for the time being. It's customary to have two versions, one for const this and one for non-const this to maintain the best const -correctness. It would go like:
CString tagInputFields::operator[](int idx)
{
switch ( idx )
{
case 1: return field1; break;
case 2: return field2; break;
default:
return _T("");
}
}
const CString tagInputFields::operator[](int idx) const
{
switch ( idx )
{
case 1: return field1; break;
case 2: return field2; break;
default:
return _T("");
}
} Yes, the two are identical except for the function prototype. That is, again, pretty normal since you are returning the same thing in each case, it's the prototype that makes the data const or not.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
"Linux is good. It can do no wrong. It is open source so must be right. It has penguins. I want to eat your brain."
-- Paul Watson, Linux Zombie
|
|
|
|
|
Thanks for the help Mike, I'll give that a try and see how it works out.
Thanks again.
- Aaron
|
|
|
|
|
How can i know name of the currently running application in win 2000? Where they are stored ,is it they are in windows registry? give me some api.
|
|
|
|
|
maybe this[^] will help
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
|
|
|
|
|
Check GetModuleFileName in MSDN
...Plug & Pray...
|
|
|
|
|
Hi all,
I try to make simple program (from msdn sample) to encrypt data using Visual C++ 6, this is the program :
#include <wincrypt.h> // CryptoAPI definitions
#define MS_DEF_PROV "Microsoft Base Cryptographic Provider v1.0"
#define PROV_RSA_FULL 1
BOOL bResult;
HCRYPTPROC hProv;
// Attempt to acquire a handle to the default key container.
bResult = CryptAcquireContext(
&hProv, // Variable to hold returned handle.
NULL, // Use default key container.
MS_DEF_PROV, // Use default CSP.
PROV_RSA_FULL, // Type of provider to acquire.
0); // No special action.
// Release handle to container.
CryptReleaseContext(hProv);
but when I compile those codes, I get error messages like this :
error C2065: 'HCRYPTPROC' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'hProv'
error C2065: 'hProv' : undeclared identifier
error C2065: 'CryptAcquireContext' : undeclared identifier
error C2065: 'CryptReleaseContext' : undeclared identifier
I don't understand, these codes is very simple and I capture these codes from MSDN (so it must be success). Can anyone help me ?
Thanks
|
|
|
|
|
I know this sounds like a stupid question but you have included 'WinCrypt.h' haven't you?
I have not tried the code myself but normally this would be the first thing I would check.
You might also need to link against Advapi32.lib as well.
If I get chance then I will try and build the MSDN code and see why it does not work - but it looks like it's just the TYPSDEF's that it can't find - so try and include the header file and hopefully that should sort it out
Mark.
|
|
|
|
|
add following line b4 including "wincrypt.h"
#define _WIN32_WINNT 0x0400
greatest thing is to do wot others think you cant suhredayan@omniquad.com>
messenger :suhredayan@hotmail.com
|
|
|
|
|
yes, I have to define
#define _WIN32_WINNT 0x0400
before #include <wincrypt.h>
Thanks
|
|
|
|
|
In my edit control derived class I need to make it so that when the user hits the enter key that the control's focus is killed, how can I do that?
|
|
|
|
|
send the WM_KILLFOCUS message
|
|
|
|
|
In Windows, exactly one window must have the focus at all times. So, simply sending a WM_KILLFOCUS to the edit control won't do anything. You have to explicitly call SetFocus() on another control to give it the focus to remove the focus from your edit control.
Hope this helps,
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I am programming a word game with a 3d engine that has a scripting language, but next to no string support, so I am trying to write a little plugin in C++ to do most of the string functions for me. Basically,I have a HUGE word list in a text file that I already split up into 26 individual files of different letters. Even still, each text file has about 10,000 words in it!! I need a way to check for the existance of a word in one of the files (not in part of a word in the wordlist, but AN ACTUAL WORD IN THE WORDLIST). Unfortunately, I don't know too much about external file i/o in C++ so I am kind of confused as to where I should begin. I know that I can't just scan through each individual word in the text file, and compare it with the word that I am looking up. That would take forever. I thought that what I could do was try to limit the scope of the searching by indexing through the file and checking the second and third letters of the words, and narrow down the scan that way. My problem is that I don't know if its even possible to move through a text file as if it were an array (eg. by line number). If its not, than must I place each word into a huge string array? Once the array has been created, things should go fast, but I have a feeling it would create quite a loading time to fill such a humungus array 26 times! I also may be approaching this problem completely wrong, so feel free to give a completely different spin on the problem. If anybody has any answers for me, I would greatly appreciate it. Thanks again!
Andrew
|
|
|
|
|
You can read the data in, then create a small program to export the data to the
{"word1", "word2" ... } text file format, then turn this into an include file. With this this as an array, you can further optimize by putting it into a hash table, or a binary string array. (do a search in CP for more information)
My neighbours think I am crazy - but they don't know that I have a trampoline. All they see my head bobbing up and down over the fence every five seconds
|
|
|
|
|
I have a program that basically acts like a menu and all functionality is added using DLL's. I am wondering how to pass data to a DLL when initilizing it. For example I would like to pass:
1) Version number
2) Handle to calling window
3) Handle to misc helper DLL's
4) Pictures Directory
5) Music Directory
6) etc
How do you do this?
Thanks,
Steve
|
|
|
|
|
You can either call a Init method and pass all these parameters to the dll...
or passthem as the parameters to the corresponding api that needs it.
*Warning* If you pass handle of the calling window to the dll and you make it global in the dll.. You will have lot of problems. Avoid global variables except for constants.
MSN Messenger.
prakashnadar@msn.com
Tip of the day of visual C++ IDE.
"We use it before you do! Visual C++ was developed using Visual C++"
|
|
|
|
|
So, could I just pass a struct to the init method?
struct info
{
CString Version;
CString MusicDir;
CString PictureDir;
};
The reason I am wanting to pass in the handle of the calling window is that I want to be able to pass messages to it. Is there another way? I built in my plugin interface a way to pass messages to the plugins but I don't know how to send messages to the main application ( Dialog app in my case ).
What kind of problems are you refering to in your warning?
|
|
|
|
|
smesser wrote:
What kind of problems are you refering to in your warning
Its the problem related to multithreading... What if two applications load your dll and pass handle to window...
if you make it global then which window will it refer to.
Check Thread Local Storage for that matter.
You can use callback functions to notify back the messages.
MSN Messenger.
prakashnadar@msn.com
Tip of the day of visual C++ IDE.
"We use it before you do! Visual C++ was developed using Visual C++"
|
|
|
|
|
Mr.Prakash wrote:
What if two applications load your dll and pass handle to window...
if you make it global then which window will it refer to.
Each application will get a separate copy of the application data, unless the data section in the DLL is marked as "shared". I think what you mean is two threads from the same application call the Init function with different windows, then there will be a problem as you have indicated. But if the Init function is only called from one thread, then there is no problem using a global variable.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Thanks for the explanations all.
Mr.Prakash wrote:
You can use callback functions to notify back the messages.
Could you elaborate on this point? How would a callback function notify back to the calling application.
So that you understand my set up. My main application is a dialog based application and so are the plug-ins. So lets say a plug-in wants to tell the main application that a song has just ended (end of song event).
Thanks
|
|
|
|
|
Declare a pure virtual class that your dialog etc will inherit from. Then you pass a pointer to your dialog across to the dll and it calls the functions it required on this calss object:
class MyCallBacks
{
virtual void Callback1(parameters) = 0;
virtual bool Callback2(parameters) = 0;
}
CMyDialog : public CDialog, public MyCallbacks
{
void Callback1(parameters);
bool Callback2(parameters);
}
So when you init your DLL, pass a MyCallBacks* pointer in the structure across. Then in the DLL, if you need to do a certain actio, you would do:
if (m_pCallback != NULL)
{
m_pCallback->Callback1(parameters);
}
Hopefully this makes some sense!
Roger Allen - Sonork 100.10016
Strong Sad:
Clever I am? Next to no one.
Undiscovered and soggy.
Look up. Look down. They're around.
Probably laughing. Still, bright, watery.
Listed among the top. Ten.
Nine. Late night. Early morn.
Early mourn. Now I sleep.
|
|
|
|
|
Yes, that makes sense.
Thanks
|
|
|
|