raptr_dflo 48 Posting Pro

At the risk of being blunt, your code (at least as posted) cannot possibly be correctly identifying widgets with the work "type" in the widgetName element, because you're checking the age element (converted to a string).

Other than that, because you're checking each element with the correct name (or will be, once you fix that bug), and then keeping track of the maximum age value, and the vector-index of the corresponding element, you -are- in effect "storing that widget's info for comparison". The element is already stored in the vector, and the index allows you to get back to it at any point. If you wish, you can more explicitly copy the Element of interest into a separate variable, and perform your comparisons against that, including when to replace it with a new Element, but remember to keep track of the case where you haven't yet found any valid element, and at the end of you loop, check whether any elements with "type" in the widgetName were found.

Which reminds me, if you keep the code more or less as-is, be sure to initialize both highest_age and highest_age_index to sensible values (maybe -1 for both). Especially for the index (currently default-initialized to zero), if you go through all the widgets in your vector and don't find any with "type" in the widgetName, at the end of the loop, you'll incorrectly believe that element zero had the maximum age (of zero), even though it was never considered as a …

raptr_dflo 48 Posting Pro

I'm sure there are plenty of educated opinions on how to perform arbitrary type-conversions. Mine is: exceptions and exception-handling are important where you have insufficient control over determining whether an operation will succeed, but using the tried-and-true method of returning a success/failure indication is preferred, simply because it is more efficient (exception handling takes place outside of the normal function-call (and other lexical scoping) stack. Of course, I was raised in the pre-OO dinosaur days, and my early training has stuck with me.

On the opposite side of the argument, exception-handling may be thought of as more elegant. A divide-by-zero error 8 function calls deep doesn't need to be error-handled through each intervening function, and you can code "in the positive" ... assuming that everything will work correctly which is mostly the case, rather than laboriously making every function responsible for verifying the validity of its inputs and checking the success/failure status of every function called from within it: the argument here is that easily 80% of the code in a non-trivial function can end up being error-checking, rather than actually accomplishing the intended task.

For your specific use-case, you can certainly check the success of the ">> convertTo" operation (but remember to return "true" rather than "convertTo"), but what happens if your From-type or To-type don't implement a stringstream & operator<<(...) or stringstream & operator>>(...), respectively? Then you still get an exception, and you haven't handled it!

Mike wrote up an excellent discussion in

raptr_dflo 48 Posting Pro

I just googled "C++ ODBC example" and the first hit seems to be sufficiently useful. You will likely have to adjust various constants in the code, particularly the query and result handling in lines 55-69, and reformat it to match your own coding style (preferably without the goto's), but I'm betting it will work for you more-or-less as-is. If you run into problems, post your code back here and I'm sure somebody will be happy to help.

raptr_dflo 48 Posting Pro

After it prints the permutation, it decrements level, returns the k'th element of Value to 0, and returns from this call of visit() to where it was called from -- in this case back to line 23 of the previous call to visit() and it continues with the for-loop. This is the essence of recursion(): the function calls itself, presumably with different parameters and some notion of when to stop calling itself so it doesn't get stuck forever. Instead of:

function a() calls function b(), which calls function c(); when function c() returns, control picks back up in function b(); when function b() returns, control picks back up in function a()

you have:

function a() calls iteslf, which calls itself; when the third invocation returns, control picks back up in the second invocation; when the second invocation returns, control picks back up in the original.

raptr_dflo 48 Posting Pro

You already have a "double if statement":

...
    if (widgetFinder.find("type", 0) != string::npos){
        if (widgetTypes[i].age > highest_age){
            ...

You just need to make sure you assign the correct member of widgetTypes (widgetName, not age) to your widgetFinder string.

raptr_dflo 48 Posting Pro

I think the problem is that you've declared it as a member function. Make sure the function is written as Mike said, e.g.

Element operator + (int a, const Element& b)  // note: not "Element::operator +"
{
    Element return_val;
    // make return_val be the sum of a and b
    return return_val;
}

and declare the function to be a friend of your class:

class Element {
    public:
        ...
        friend Element operator + (int a, Element & b);
        ...
};

Do the same for all three versions of your operator+.

raptr_dflo 48 Posting Pro

No idea, especially since the line-numbering in the code you provided doesn't correspond to the line-number in the error messages. Perhaps replacing the '.' with another '::' would work?

_FtpWebRequest->Method = System::Net::WebRequestMethods::Ftp::UploadFile;
raptr_dflo 48 Posting Pro

At line 11 of your functions code, in Write_maps(), your cast-to-integer doesn't do anything. The expression is equivalent to (int(Time))/TIMESTEPS , and Time is already an integer.

TIMESTEPS is presumably also an integer, but you apparently have it defined globally (if you can access it in Write_maps()) and also locally in your main(). If you already have it globally available, you don't need it in main(), and it just invites problems since if you want to change it, you need to change it in more than one place.

And if both values are integers, then the division results in an integer, so no cast is needed anyway.

How does your Check_exit() function know the value of Time (also local to main())?

And what is the last filename printed out in your "Filename = ..." line?

raptr_dflo 48 Posting Pro

While system() commands can be convenient to write, they are quite inefficient (your program is running under one shell, and each system() first spawns a new shell, then runs the specified command in that shell), and their use is generally considered poor programming practice.

Instead, consider using the rename() function to rename and move the file in one step (if that is possible on your system, it may require that the source and destination locations be on the same disk partition). If that fails, you may have to copy the contents of the file to the new location (open old file for reading, new file for writing, read data from old and write to new until there's no more data to read, close both files), and then delete the original file using remove() (reference can be found on the same site as above).

raptr_dflo 48 Posting Pro

Your .move() and .show() look ok to me. Have you verified that x and y aren't changing (using getX() and getY())? Have you verified that dx and dy are indeed non-zero for each bullet? Also, do you remember to call SDL_Flip() (or whatever it's actually called, I don't have an SDL reference open at the moment) after drawing everything for that frame?

raptr_dflo 48 Posting Pro

You are correct that you don't want the height, weight and getter/setter methods for them to be static members of your class, or you can't have multiple instances with different values. So you need to fix that first, and then deal with where your Person-instances will live.

First of all, in your click-handler callback method TForm1::CreatePersonClick(), you have created a local instance of class Person, which will be destroyed when control returns from the function. There are a variety of ways to deal with this, depending on how you want to handle your TForm1 -- if the form will be dismissed after you create a person, then you can have your Person instance object be a member of the TForm1 class, and provide a pubic GetPerson() method which returns a reference to it, so TForm2 can call TForm1::GetPerson(); or if you want TForm1 to stay visible and create a new Person from the current values each time the user clicks the button, then (if you want to store the person for further use) you need to add the person into a vector<> or other container, and either pass it as an argument to the constructor of TForm2 when you create the second form, or provide a TForm2::SetPerson() method that your CreatePersonClick() method can call after it creates the TForm2 object.

I can provide you some simple code that does any of these things, but I'm not yet clear what exactly you want your program to do. I think …

raptr_dflo 48 Posting Pro

So what should the find() method be operating on? So far, GreyWolf has written the only code here, other than your definition of your struct. Where's -your- code?

raptr_dflo 48 Posting Pro

Whether your program uses loops has nothing to do with whether it handles non-ASCII input.

I found this at cplusplus.com

As part of the iostream library, the header file <iostream> declares certain objects that are used to perform input and output operations on the standard input and output.

They are divided in two sets: narrow-oriented objects, which are the popular cin, cout, cerr and clog and their wide-oriented counterparts, declared as wcin, wcout, wcerr and wclog.

The "wide-oriented" variants don't necessarily support full unicode, but might be sufficient for your needs.

Are you specifically not supposed to use loops? Your code as written is already nearly impossible to maintain, and won't handle an input string longer than 11 (or however many) characters....

raptr_dflo 48 Posting Pro

Actually, I have an assignment from school in which i have to simulate the functioning of a dialog box in dos.

What does this assignment have to do with capturing screen-display into a file? Your program knows what it displayed on the screen previously, just re-display that when you're finished with your simulated dialog box. Depending on the details of which compiler you're using for school, you may be able to use

system("cls");

as a non-portable way to clear the screen before drawing the dialog box, and after "closing" it and re-displaying what was there previously. Once you have more basic stuff done, you may want to look into a "curses" library for better control over where text is displayed in your terminal window, but that sounds more advanced than you really need. Not to mention trying to go back and scrape the current contents of your window into a file, and then read that file back and re-populate your window from it.

raptr_dflo 48 Posting Pro

You're resetting your row1, ... counters to zero inside your play-loop.

Your code may be easier to follow if instead of trying to maintain the state of each row/column/diagonal each time the user strikes out a number, you just manually do the check. It will be marginally slower, but at only 25 squares to check, I don't think you'd notice! E.g.:

...
    a[i][j] = 0;

    // check if row is now clear
    bool row_clear = true;
    for (int jj = 0; jj < 5; jj++) {
        if (a[i][jj] != 0) {
            row_clear = false;
            break;
        }
    }
    if (row_clear) {
        // do appropriate thing
    }

    // check column
    // if i == j, check primary diagonal
    // check other diagonal if appropriate

    ...

And for increased modularity, you might want to split that code into additional methods, e.g.:

bool bingo::is_row_clear(int i) {
    ...
}

and then call these new methods from your bingo::play() method.

raptr_dflo 48 Posting Pro

Hey Vusuzumi, I'm just catching up with this topic, and I think you've started at least three threads for the same program and basic flow questions (about handling your gender-validation issue). If any are now resolved, please mark those threads "solved". And in the future, please follow up with your revised code and new questions in the same thread, so those of us trying to help aren't chasing your thought-flow around, and potentially answering your question in one thread when somebody else has already answered in another thread. Thanks!

As far as this one, I'll reword the assignment: you need to edit your existing main() function so that it first prompts the user for the number of students (10 in the first line of the example input), then puts the rest of the functionality into a loop which executes that many times. Finally, add a couple of lines into your code so that a total-amount-of-money is accumulated for all ten (or how ever many) students is computed, so that the class teacher knows how much money he/she should have once all ten (or how ever many) students have paid the proper fee.

Does that help?

raptr_dflo 48 Posting Pro

What is the question? And is this supposed to be C++ code, or Java?

"P U Q" is normally called a "union", not a "sum".

I'm not sure why you keep checking that elements of multiset are not zero in sum(), intersection() and difference(). Zero is a perfectly reasonable value, and it needs to be handled (not skipped).

P.S. When posting completely unrelated code with a new question, please start a new thread. And did you get your questions answered from your previous assignment?

raptr_dflo 48 Posting Pro

Hi Vusumuzi,
What do you mean by "discounts look screwy"? What inputs are you sending into the function, and what result are you getting back?

The "random numbers" look to me like they represent "number of students" (10) and "number of sports activities" and "number of other activities" for each student. There are 11 pairs of input values, because the row with 4 and 5 should generate an error and prompt the user to re-input the values.

raptr_dflo 48 Posting Pro

Yes, you should use an if-then-else-if structure in your discFee() function. The usage of the function is provided at line 31 above -- that should give you a pretty good idea how the function should be declared: it will take three arguments instead of two.

Also, in your calcFee() function, why not use the constants feeSport and feeOther provided for you, instead of the "magic" numbers 100 and 120?

raptr_dflo 48 Posting Pro

Your program (for value 5) appears to draw lines up to 5 characters in length, and then back down. The correct output would be a TOTAL of 5 lines. What is the maximum length of a line in this case? What do you think the program should display if you give it an even value like 6? The program you have so far (without even seeing it) is obviously doing the right thing for -some- value, so you're very close.

raptr_dflo 48 Posting Pro

Well, what holds the data for the stack? And where is the top element in that data? I'll post the correct code in a couple hours (if I remember), but see if you can get it first! :)

raptr_dflo 48 Posting Pro

And when you post your code, please also mark the thread as "solved". Great work! :)

raptr_dflo 48 Posting Pro

Right at line 1, you've omitted the class-name, unless that was a copy-and-paste error:

string Vigenere::encode(string text){

Could that be the problem? Otherwise, your code looks fine. Try one more cout right before your return from encode():

cout << "final encrypted text: " << line << endl;
raptr_dflo 48 Posting Pro

At this point, you're learning the nuances of dealing with an array vs. a std::vector. One benefit (out of several) of using a vector, is that it maintains its own size for you. With the array, as you're discovering, along with the array itself (or pointer to element zero, the two are essentially interchangeable), you need to pass some indication of how many elements are in it -- either a numeric size, which is the more accepted idiom, or a pointer to the last element or one-past-the-last-element, if that provides a more natural expression of what you're trying to accomplish.

raptr_dflo 48 Posting Pro

It is a function. It's name is operator<<, and you could in fact call it as, for instance, operator<<(cout, myList); . But it's name makes it a special kind of function which overloads the "<<" operator, so that you can more naturally specify cout << myList; .

You can overload mathematical operators for your own classes as well, so that if you were to create (for instance) a rational-number class:

class Rational
{
protected:
  int numerator;
  int denominator;
public:
  Rational(n, d);
  ~Rational();
  Rational operator*(const Rational & other) const;
  ...
};

...

Rational Rational::operator*(const Rational & other) const
{
  int n = numerator * other.numerator;
  int d = denominator * other.denominator;
  return Rational(n, d);
}

...

int main(int argc, char * argv[])
{
   ...
   Rational r1 (3, 5);  // r1 = 3/5
   Rational r2 (4, 7);
   Rational r3 = r1 * r2;  // invokes Rational::operator*()
   ...
}
raptr_dflo 48 Posting Pro

I'm not sure how efficient it is to pass copies of the codeArray around, but the feel is nicely recursive. Note that once you've captured codeArray.size() into s, you can use that in your call to codeArray.resize(), and that you only need to resize codeArray once. Otherwise I'm concerned that your codeArray is twice as big as it needs to be, and you're only filling alternating positions in it. Double-check by printing out the size and contents when you insert it at line 7, for a known code value.

raptr_dflo 48 Posting Pro

Your problem isn't with your stack code. I copied it and wrote a simple main() that pushed three constant strings onto it, and it behaved as expected. Instead, understand what strtok() is doing: it's internally maintaining a static pointer to the next token in the string, and returning that. Since you're pushing the returned pointer onto your stack, you're actually putting the same pointer on your stack over and over, while the next call to strtok() changes what all of those identical pointers now point to!

So, if you're determined to stick to char *, you could do stackPush(strdup(token)); , where strdup() is making a copy of the token for you (and don't forget then that since you're effectively calling malloc(), you're also responsible for calling free() on each string as you remove it from the stack, once you're done with it). Or you could take mike's advice and make a string-type via std::string str (token); and push that on a stack of strings, and the memory will be allocated and released for you by the string class.

raptr_dflo 48 Posting Pro

Your code looks ok at first glance, as far as adding integers. Have you tested it yourself? If it doesn't work, what is it doing wrong?

Ravenous' code will certainly get the information from the text file, but at his line 20, his comment tells you that you now have to parse the information out of the line that you read from the file and do something with it.

Now that you have a line (instance of string), you can create a stream from it:

stringstream inTxt (line);

.
Then you can use inTxt pretty much exactly the way you use inFile, to read items out of line. You just need to check when inTxt is empty (use one of .good(), .bad(), .eof()) so you know when to get another line from inFile. If you are sure that integers and operators will always be separated by whitespace, you could read a string out of inTxt each time, and provide and call your own functions isInteger() and isOperator(). You could declare isInteger as:

bool isInteger(const std::string & str, int & val);

and have it return true if str represents an integer (and store the integer value into val), or false if str does not represent an integer (and leave val alone).

If the input can skip spaces between integers and operators, e.g. 3+5 instead of 3 + 5 , then you may need to iterate over line one character at a time, deciding what to …

raptr_dflo 48 Posting Pro

I haven't tested it, so apologies if I have any syntax errors in it, but try this:

string Vigenere::EraseChar(string str){
    for(int i = 0; i < str.length(); i++){
        bool inAlph = false;
        for(int j = 0; j < 21; j++){
            if(str[i] == ALPH[j]){
                inAlph = true;
                break;  // don't need to keep checking against the rest of ALPH
            }
        }
        if (!inAlph) {
            str.erase(i,1);
            i--;
        }
    }
    return str;
}
raptr_dflo 48 Posting Pro

No values in your code are "changing permanently". When a key is pressed, an event is triggered, you catch the event, and you assign a value to your message variable. As soon as you blit your message, you set your message variable back to 0. That doesn't look permanent to me. If you wish to keep the displayed message visible, then (as you noticed yourself), don't blit the background over top of it every time through your while(run) loop. In fact, you shouldn't call SDL_Flip(screen) until there's actually a change to bother with.

So if you want the displayed message to persist until the next keystroke:

if ( message != 0 )
{
    blit(back,screen,0,0);
    blit(message,screen,100,300);
    SDL_Flip(screen);
    message = 0;
}

If you want to clear the message if you press any key other than up/down/left/right, then create a fifth non-zero value to assign to message as a default in your switch() statement at line 14.

raptr_dflo 48 Posting Pro

Also at line 99, what are you returning from top()? And what did you mean to return? Also, you have an assignment instead of equality-test at line 38, but I don't know what the expression is supposed to do. A close-character will never equal its open-character, and any other non-null character will ever equal the null-character. Or if you're replacing each close-character with its corresponding open-character, and all other chars with null-characters, and proceeding into the if-block only for paren/bracket/brace, that's fine, but it's not exactly human-readable. :)

Maybe instead, you could consider separate functions bool isClose(char) and char openCharForCloseChar(char) , and use those in your logic without replacing the actual characters in line[].

raptr_dflo 48 Posting Pro

Read the code you just posted, carefully. First, what are you returning? Once you fix that, if you can't see what's wrong with the code, try inserting cout << "str = '" << str << "'" << endl; before line 2, and again after line 7.

There's nothing like debug-prints for tracking down problems!

raptr_dflo 48 Posting Pro

A quick Google search uncovered this, which suggests which libraries to add to your build.

raptr_dflo 48 Posting Pro

As far as cleanliness, I don't know offhand if you need to resize your QBitArray before assigning into it, but since you know it will be the same length as your input codeString, why not start off with:

QBitArray codeArray(codeString.length());

and skip the resizing completely?

Also, the QBitArray documentation says:

For technical reasons, it is more efficient to use testBit() and setBit() to access bits in the array than operator[]().

Good luck!

raptr_dflo 48 Posting Pro

Instead of writing out to your output file every time you do something, try separating your logic into:
1) read the input file into your array
2) loop over user input, adding students to the array, removing students from the array, or editing students already in the array
3) when the user chooses "Quit", write the student array out to the output file

Consider having your search-routine return the array-index of the student you're searching for (and maybe an obvious non-index like -1 if the search fails).

Your edit function shouldn't do a search. Instead when the user chooses the "Edit" option, first perform a search using your search function, and if successful then call your edit function, otherwise print an error message that the specified student wasn't found.

raptr_dflo 48 Posting Pro

Please use [ CODE ] tags when you include code in your posts (which you should almost always be doing when you ask a new question). Select the code that you've pasted in, then click the very-clearly-marked "[ CODE ]" icon above the editor.

Since you haven't told us what your program -is- doing, it's hard to suggest what you should fix. Though there have been so many posts on almost identical issues dealing with ifstream input, I'll go out on a limb and suggest that you add the line inFile.ignore(); after you read the year and before you increment "counter" inside your while loop in fillVector().

raptr_dflo 48 Posting Pro

Continuing on, yes, no need to call line a "variable" in quotes. It IS a variable, so of course you can treat it like one. So are inFile and outFile.

inFile is called an "instance" of class ifstream. outFile is an instance of class ofstream. line is an instance of class string. See this for a list of supported operations on string instances. There are also good tutorials on that site.

raptr_dflo 48 Posting Pro

dyboss, thanks for the assignment text, what code have you written so far?

raptr_dflo 48 Posting Pro

Hmmm, I just noticed you included the keyword 'class' at line 11 of your header file above. Instead I think what you need to do is "forward declare" your editor class by adding a single line before line 3:

class editor;

and then remove the word "class" in front of "editor" inside your Tmixala class.

Meanwhile, I looked up "TForm" to see that you're using the Delphi GUI SDK. Again, I haven't programmed in it myself, so I don't really know much about how it's supposed to work. In your editor class, when you get a resizeWindow() callback, you recompute member variables Width and Height, but how does the TCanvas instance find out about its new size?

raptr_dflo 48 Posting Pro

You have a spurious semicolon at the end of line 74.

Your EraseChar() method is still incorrect. See what happens if you have two or more successive characters not in the range 'A'-'Z'.

In encode() and decode(), what is the value of k_index if key isn't one of the characters in ALPH? Same for t_index and text? If key and text are only supposed to contain characters from ALPH, then you still need to rewrite EraseChar() to remove the non-ALPH characters.

Try adding cout lines after you've called StringToUpper() on key, and again after you've called EraseChar(). Make sure your input key has a mix of lower and upper-case letters, both within ALPH and not, along with some numbers and punctuation symbols, to make sure those two functions are working as intended.

raptr_dflo 48 Posting Pro

Each unique solution has 4 possible rotations (original, 90 degrees, 180 degrees, 270 degrees) and for each of those, 3 possible inversion/reflection states (original, reflected left-to-right, reflected top-to-bottom [*]). Once you have one of your solutions (knowing which column the queen is in for each row), how would you come up with rotated/inverted versions of that solution, to compare against saved unique solutions? And how would you save a solution as a unique one, once you determined it wasn't a rotated/inverted version of an previously-found solution?

[*] Note that reflecting a solution left-to-right AND top-to-bottom is the same as rotating it 180 degrees. As a result, reflecting a solutions left-to-right is the same as reflecting its 180-degree rotation top-to-bottom, and vice versa, so I'm pretty sure that makes 8 non-overlapping states for a single unique solution.

raptr_dflo 48 Posting Pro

So you're trying to write a 'bot which might, for example, automatically click into the fields on a displayed web-page and enter specific text data for you?

Anyway as far as your mouse-link, the first note at the top of the page says the function has been superseded, and provides a link to the updated function to use instead. As far as "getting code to compile using your compiler", it looks like you're one of very few users on this forum using the latest and greatest tools on Windows, so what exactly is the problem you're having compiling your code?

raptr_dflo 48 Posting Pro

All other bickering aside ;), it looks like a big part of the problem might be your re-use of variable n at line 19. Each time through the inner loop, you re-assign n based on loop-variable a and the previous value of n. I don't think that's what you meant to do. Looping over a and b is probably fine, though I'm not sure why you loop over a using n+1 and k-1, and then loop over b using i and j (which are assigned to be those same two values). But inside those loops, you may want to call a function such as:

bool productHasFactors(int a, int b, int n)
{
   ...
}

which determines if a*b-n is divisible by a-n and b-n, and returns true or false accordingly.

Also, as Cross213 suggested, you may wish to add a prompt at line 9, such as cout << "Enter lower and upper bounds for the search: ";

raptr_dflo 48 Posting Pro

You may wish to look into the 7-Zip archiever/compressor, and specifically the LZMA compression SDK at http://www.7-zip.org/sdk.html

raptr_dflo 48 Posting Pro

Think about what you need to do. At lines 66-72 you look for a square matching the number, and if you find it, you set it to zero. That much is good. You might want to include code to print an error to the user if he entered a number that isn't on the board.

The check for whether the diagonal is completed can be done separately, if a square was successfully cleared. In fact, you only need to check the top-left to bottom-right diagonal if i == j for the number found and cleared. You will also want to check if row i is clear, if column j is clear, and (I leave the logic to you) if the top-right to bottom-left diagonal is clear.

In addition, your check for whether any number is repeated isn't complete, it only checks whether two adjacent numbers are the same, and has an indexing error at the right-hand edge of each row.

raptr_dflo 48 Posting Pro

I haven't tried whichever GUI SDK you're using, but I'm concerned about the lack of information provided to the Canvas object. How does -it- know which font to use? Does the same tab always display the same way (whether correctly or incorrectly), or will it display one way, and then if you go to another tab and come back to the first one, it displays differently from how it did before?

raptr_dflo 48 Posting Pro

There are binary distributions available for download for both generic and MSVC-specific needs, at http://curl.haxx.se/download.html#Win32, something there should work for you.

raptr_dflo 48 Posting Pro

Your error message indicates that you're not linking your executable against whatever library contains the compiled implementation code for GetEncoderClsid(). Go back to the documentation on MSDN, there's probably something there that tells you what library you need to specify in your Build set-up.

raptr_dflo 48 Posting Pro

"myPM" is returning something to do with DLLFunc2 (at line31), but lines 51 and 76 are assigning DLLFunc (again) instead of DLLFunc2.

raptr_dflo 48 Posting Pro

It looks like you can export the public-key into a BLOB using CryptExportKey() (http://msdn.microsoft.com/en-us/library/aa379931%28v=vs.85%29.aspx), but then the BLOB is only usable via CryptImportKey(). You can also export/import the public/private key combo. The private key is private, thus there is no way to export it separately.

Instead, you're supposed to use the opaque HCRYPTKEY handle returned from CryptGenKey() (or CryptImportKey(), assuming you've already generated a key) to encrypt data to be sent or to decrypt data received.

You may find what you're looking for in the sample code here:
http://msdn.microsoft.com/en-us/library/aa382370%28v=vs.85%29.aspx
or in the other sidebar links.