|
Hi, I tested the atol() function. This line works fine:
char buffer[] = "1234567890.12";
long number = atoi(buffer); // number = 1234567890;
but here is problem after I added the following lines:
buffer[10] = '\37'; // buffer = "1234567890712" now
number = atoi(buffer); // return value is 1912276760. why?
thank you very much for your advice!
|
|
|
|
|
sorr, typing error:
buffer[10] = '\37'; ==> buffer[10] = '\x37';
|
|
|
|
|
A long is a 32 bit number.
The biggest it can store is 4294967295
1234567890 < 4294967295
But
1234567890712 > 4294967295
That's why you get this overflow error.
Nish
Nish was here, now Nish has gone;
He left his soul, to turn you on;
Those who knew Nish, knew him well;
Those who didn't, can go to hell.
I like to on the Code Project
Sonork ID 100.9786 voidmain
www.busterboy.org
|
|
|
|
|
Ah, I see. Thank you, Nish.
|
|
|
|
|
I'm trying to figure out how this beast is supposed to work to be able to show popup contextual help windows?
The tech-writter gave me a help.chm file that has a [TEXT POPUP] section in it with the text file that contains all the contextual help descriptions like :
context.txt :
.topic HID_TOPIC_DO_SOMETHING
This functionnality will do something
and context.h :
#define HID_TOPIC_DO_SOMETHING 4567
in my program I'm doing the following:
HH_POPUP popupText = { sizeof(HH_POPUP),
theApp->m_hInstance,
4567,
NULL,
{100, 100},
(DWORD) -1,
(DWORD) -1,
{-1, -1, -1, -1},
NULL
};
::HtmlHelp(m_hWnd,helpFile, HH_DISPLAY_TEXT_POPUP ,(DWORD) &popupText);
But it doesn't work really well, it doesn't work at all, I don't know exactly what happening, but the topic is not found!
Is this supposed to work ? Should it be used ? the documentation in MSDN is not really usefull, and what I could find on the web, wasn't really usefull either!
If you have any hints, tips or additional resources for this I'd appreciate !
Thanks!
Max.
|
|
|
|
|
Here is the code I use
static HWND DoHtmlHelp (HWND hwndCaller,
LPCTSTR pszFile, UINT uCommand, DWORD dwData)
{
#if !defined (_WIN32_WCE)
CWaitCursor wait;
if (hwndCaller)
{
CWindow wMain;
wMain .Attach (hwndCaller);
wMain .SendMessage (WM_CANCELMODE, 0, 0);
wMain .SendMessageToDescendants (WM_CANCELMODE, 0, 0, TRUE);
}
HWND hWndCapture = ::GetCapture ();
if (hWndCapture != NULL)
::SendMessage (hWndCapture, WM_CANCELMODE, 0, 0);
return HtmlHelp (hwndCaller, pszFile, uCommand, dwData);
#else
return NULL;
#endif
}
static HWND DoHtmlHelpPopup (LPTSTR pszHelpFile, HWND hWndCtrl, DWORD dwID)
{
#if !defined (_WIN32_WCE)
RECT rect;
::GetWindowRect (hWndCtrl, &rect);
HH_POPUP pop;
pop .cbStruct = sizeof (pop);
pop .hinst = NULL;
pop .idString = dwID;
pop .pszText = NULL;
pop .pt .x = (rect .left + rect .right) / 2;
pop .pt .y = (rect .top + rect .bottom) / 2 + 8;
pop .clrForeground = -1;
pop .clrBackground = -1;
pop .rcMargins .left = 20;
pop .rcMargins .top = 8;
pop .rcMargins .right = 8;
pop .rcMargins .bottom = 8;
pop .pszFont = NULL;
return DoHtmlHelp (hWndCtrl, pszHelpFile,
HH_DISPLAY_TEXT_POPUP, (DWORD) &pop);
#else
return NULL;
#endif
}
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
i am making a text editor and i would like a encrypt button that will change the text in a TRichEdit1 box to some form of encryption. i need a password to be entered on encryption that must be put in again to decrypt the text back to what it was
any code or sources would be greatly appreciated
thanks in advance
Steven Richardson - soveryevil@hotmail.com - you can contact me on MSN messenger at that address or email me on it
|
|
|
|
|
Perhaps you might want to use the PGP API.
Or look up "Cryptographic Functions" on MSDN
If you have trouble finding it, look for CryptEncrypt and CryptDecrypt
Nish
Nish was here, now Nish has gone;
He left his soul, to turn you on;
Those who knew Nish, knew him well;
Those who didn't, can go to hell.
I like to on the Code Project
Sonork ID 100.9786 voidmain
www.busterboy.org
|
|
|
|
|
I have a project that uses the CHtmlView MFC View and I want to feed the control the html text, rather then have it get it from the web or a file. There doesn't seem to be a way to do this.
For example, I just want to display this in the CHtmlView:
<html><body><b>Hello World</b></body></html>
How can this be done?
|
|
|
|
|
http://www.codeproject.com/useritems/parse_html.asp
Nish
Nish was here, now Nish has gone;
He left his soul, to turn you on;
Those who knew Nish, knew him well;
Those who didn't, can go to hell.
I like to on the Code Project
Sonork ID 100.9786 voidmain
www.busterboy.org
|
|
|
|
|
Hi. I want to thank everyone who has helped me answer many of my questions. However, it seems like the questions just keep coming.
I am tryingto use Openprinter and also GetPrinter to see if a printer is offline/connected or not. However, I am having some trouble with the structure of the call.
PRINTER_INFO_2 Printer2;
GetPrinter(
hPrinter, //printer handle
2, //level 2
Printer2, // Buffer that holds the info
sizeof(PRINTER_INFO_2),
&dwNeed); //bytes still needed
However, it gives me an error about not being able to cast from PRINTER_INFO2 to unisgned char*. I also tried to allocate another buffer and type cast it manually to PRINTER_INFO_2 to try to get to the Status variable but same basic thing.
What is the problem.
Thanks in advance.
|
|
|
|
|
(char *) &Printer2
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
can any one tell me how to write a method that adds some objects to an Array.
and at the same time sort these objects using insertion sort?
thanks a lot,
|
|
|
|
|
using linked list instead of array might help.
here is some info about linked list: http://cslibrary.stanford.edu/103/LinkedListBasics.pdf
|
|
|
|
|
i cannot use anything else but arrays, it's part of my project!
any ideas??
thanks al lot
|
|
|
|
|
anonymous wrote:
it's part of my project
Recently CP has been attracting a lot of project help requests.
Nish
Nish was here, now Nish has gone;
He left his soul, to turn you on;
Those who knew Nish, knew him well;
Those who didn't, can go to hell.
I like to on the Code Project
Sonork ID 100.9786 voidmain
www.busterboy.org
|
|
|
|
|
If insertion sort is what I think it is, you insert an element into a sorted array at the right position so that the resulting array is again sorted. If you start with an array with zero elements, simply insert it at position 1. From now on for each element added, compare with each existing element till you find one that is equal or greater than it in sort order and insert it there.
Nish
Nish was here, now Nish has gone;
He left his soul, to turn you on;
Those who knew Nish, knew him well;
Those who didn't, can go to hell.
I like to on the Code Project
Sonork ID 100.9786 voidmain
www.busterboy.org
|
|
|
|
|
Well, if you absolutely have to use arrays, then the basic idea would be:
1) If your array has n items in it:
2) Search the array for the position to insert the new item, call it i
3) Create a new array of size (n+1)
4) Copy items 0..(i-1) from the old array to positions 0..(i-1) in the new array
5) Copy items i..(n-1) from the old array to positions (i+1)..n in the new array
6) Copy the new item into position i in the new array.
As Nish pointed out, this is not a really good way to do it, you should check and see if you can use a linked list, as it will perform much better.
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
And the other easy method of sorting is a bubble sort. this is efficient for small lists, but sh!te for big ones. But it's simple and should score big points in class.
Search the web for the theory and have a go at implementing it (rather than just me telling you)
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
Don't forget about good ole Mr. qsort(). He loves to sort arrays. qsort() is part of the standard C library. Here is a little console application that shows qsort's useage. It will sort an array of objects and an array of pointers to objects.
#include "stdafx.h"
#include "stdlib.h"
#include "search.h"
#include "conio.h"
class Obj
{
public:
int nValue;
};
typedef int (*compfn)(const void*, const void*);
class MyClass
{
public:
Obj m_objList1[10];
int m_nList1Size;
Obj *m_pobjList2;
int m_nList2Size;
void Sort1()
{
qsort(m_objList1, m_nList1Size, sizeof(Obj), (compfn)Compare);
}
void Sort2()
{
qsort(m_pobjList2, m_nList2Size, sizeof(Obj*), (compfn)Compare);
}
private:
static int Compare(const Obj *a, const Obj *b)
{
if(a->nValue < b->nValue)
return -1;
else
if(a->nValue > b->nValue)
return 1;
else
return 0;
}
};
int main(int argc, char* argv[])
{
MyClass data;
int i;
data.m_objList1[0].nValue = 4;
data.m_objList1[1].nValue = 3;
data.m_objList1[2].nValue = 1;
data.m_objList1[3].nValue = 5;
data.m_objList1[4].nValue = 2;
data.m_nList1Size = 5;
data.Sort1();
for(i = 0; i < data.m_nList1Size; i++)
{
printf("%ld\n", data.m_objList1[i].nValue);
}
printf("%\n");
data.m_pobjList2 = new Obj[5];
data.m_nList2Size = 5;
data.m_pobjList2[0].nValue = 4;
data.m_pobjList2[1].nValue = 3;
data.m_pobjList2[2].nValue = 1;
data.m_pobjList2[3].nValue = 5;
data.m_pobjList2[4].nValue = 2;
data.Sort2();
for(i = 0; i < data.m_nList2Size; i++)
{
printf("%ld\n", data.m_pobjList2[i].nValue);
}
delete [] data.m_pobjList2;
_getch();
return 0;
}
Note if the objects you are sorting are big, sorting the array of pointers may be faster. Only the pointer values get moved around not the large objects. This also keeps you from have to write copy operators for the objects being sorted.
If you need to sort on more that one value in the object you can do something like this:
int compare(const void *a, const void *b)
{
if(a->value1 < b->value1)
return -1;
else
if(a->value1 > b->value1)
return 1;
else
{
if(b->value2 > b->value2)
return -1;
if(b->value2 < b->value2)
return 1;
else
return 0;
}
}
Hope this helps...
Jonathan Craig
MCW Technologies, Inc.
www.mcw-tech.com
|
|
|
|
|
Is anyone familiar with the error below? I am not sure what I am doing wrong, just trying to call a function compiled into a .dll in C++ from VB.
Thanks again.
I've created what I believe should be the method to do this:
1. Created a Win32 Dynamic Linked Library
a. Choose a simple .dll project
2. Wrote the function inside the header file.
3. Compiled the .dll ok and exited VC++
Launched VB
1. Added a module
2. Included the following code for the module
Declare Function SumValue Lib "sum.dll" (ByVal a As Integer) As Integer
3. Put a button on a form where I try to call the function SumValue
4. Get an error:
Run-time error '453' Can't find DLL entry point SumValue in sum.dll
Does anyone have a clue?
Thanks again
Nick Parker
Nick Parker
|
|
|
|
|
Have you declared your function like this?
extern "C" __declspec(dllexport) int WINAPI SumValue(int); If not, you might want to give it a try to see if this fixes your problem.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I use Visual C++ 6.0 Professional with Visual Studio. In the Dialog design
tool I would like to put a raised bump line or a sunken line grove onto
the dialog. The problem is that for reasons unknown to me there is no
LINE tool on the Dialog Controls Palette Tool bar. Can anyone tell me
how to design a line into my dialog at design time? Then also is there
some way to add a line tool to the Dialog Controls Tool Bar?
Thanks
Mike
|
|
|
|
|
THis bevel line control should do what you need:
http://www.codeproject.com/staticctrl/rotated_bevel.asp
Roger Allen
Sonork 100.10016
If I'm not breathing, I'm either dead or holding my breath.
A fool jabbers, while a wise man listens. But is he so wise to listen to the fool?
Please step to the rear of the car and make room for more victims. - John Simmons the Outlaw programmer, 1st Feb 2002, in the lounge
|
|
|
|
|
Thankyou very much Roger,,,,I will take a look at it.
|
|
|
|
|