|
Are you looking for the function atoi? this is an old but much maligned function. If it is you you only have to say "Thanks masked man - you have saved my life"
go cobol young man - go cobol
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
|
|
|
|
|
|
cobol just told you, how to convert from str to int so you have that right?
int x = atoi("123456");
now to change that back to an int?
ok right out of MSDN
char *string, *stopstring;
double x;
long l; // or int
int base;
unsigned long ul;
string = "3.1415926This stopped it";
x = strtod( string, &stopstring );
printf( "string = %s\n", string );
printf(" strtod = %f\n", x );
printf(" Stopped scan at: %s\n\n", stopstring );
string = "-10110134932This stopped it";
l = strtol( string, &stopstring, 10 );
printf( "string = %s", string );
printf(" strtol = %ld", l );
printf(" Stopped scan at: %s", stopstring );
string = "10110134932";
Best Wishes and Happy Holiday's,
ez_way
|
|
|
|
|
You can use the atoi() function if it a CString.
If it is LPTSTR or some other string stuff I prefer writing them on an invisible static text box and retrieving them as an interger.
I hope this helps!
Well... I am a beginner ...
|
|
|
|
|
Scolinks wrote:
You can use the atoi() function if it a CString.
If it is LPTSTR or some other string stuff I prefer writing them on an invisible static text box and retrieving them as an interger.
I hope this helps!
Well... I am a beginner ...
Yuck! (the static text box thing) But forgivable for a beginner (just )
I think it's time you were introduced to the boost library, and in particular the lexical_cast<> template.
Also note that an LPTSTR (long pointer to a TCHAR string) can be one of two things - a pointer to a char array (char *), or a pointer to a wide-char string (wchar_t *, which is a full type in VC.NET, and a typedef for short in VC6)
The T bit is the TCHAR thing mentioned earlier - TCHAR means char or wchar_t, depending on if you are building an ANSI/ASCII version of your code, or a UNICODE one.
I would suggest that you look up the relevant functions for conversions, which can handle unicode or ansi strings as necessary (eg, _tcstoul for converting a LPTSTR to an unsigned long).
HTH
--
Ian Darling
"The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky
|
|
|
|
|
Pen pen(m_LineColor,(float)m_LineWidth);
SolidBrush brush(m_FillColor);
...
graphics->DrawPolygon(&pen,ps,p);
graphics->FillPolygon(&brush,ps,p);
...
delete &pen; //
delete &brush; //
Execute application ,'delete &pen' and 'delete &brush' error.
Thanks.
VC/MFC fans.
|
|
|
|
|
Buddy you don' have to worry bout notting. We taka cara you. You no hava delete notting. You trustus.
Go FORTH and smite thine enemy sayeth Prince George
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.E. You do not and never will have to delete objects that you have defined without the new operator. This is not GDI+ - this is basic C++ .
The fourth moon is casting a shadow over Jupiter at this very moment
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
|
|
|
|
|
LPRECT rect;<br />
<br />
rect->left = 100;<br />
rect->right = 200;<br />
rect->top = 100;<br />
rect->bottom = 300;
This is the code that should be executed when i click a button. However, when I click it, I get an error, it terminates my process. Why?
|
|
|
|
|
LPRECT rect = new RECT;
rect->left = 100;
rect->right = 200;
rect->top = 100;
rect->bottom = 300;
//must delete rect later;
Thank You
Bo Hunter
|
|
|
|
|
|
Don't use LPRECT. Basically that means CRect *pRect, which is probably not what you really want. Use RECT instead. Then you can create an object just like something else.
MFC uses CRect which can implicitly cast to RECT. This class contains some really handy methods. For instance Width() and Height().
|
|
|
|
|
Hi ,
I've written a Win32 DLL in C that gets called by an application. I spawn a Dialog Box from within this DLL using DialogBox ; I would like to give this box a parent window but I'm not able to find a way to specify a valid parent window handle suitable for a call to DialogBox.
Does anyone know how to achieve that?
Thanks for your time & help
Marc
|
|
|
|
|
The caller should pass a parent window to your code. See various APIs like ShellExecute() that do this.
If you can't change the caller, you'll have to resort to either enumerating windows in the current thread, looking for an overlapped window, or call GetActiveWindow() and hope it's suitable.
--Mike--
Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber
If my rhyme was a drug, I'd sell it by the gram.
|
|
|
|
|
Mike,
Indeed, I can't change the caller so I've used the GetActiveWindow API and this provides me what I was looking for.
Merci beaucoup de ton aide ( j'ai lu sur ton site web personnel que tu as étudié le français ... alors je ne peux résister )
Marc
|
|
|
|
|
Hi..
I used the ADO data bound Dialog wizard to use an access DB table (ID:Autonumber , title:text , description:MEMO)
this code adds a new record:
UpdateData();
_variant_t varIndex;
_variant_t varVal;
try
{
m_pRs->AddNew();
varIndex.vt=VT_I4;
varIndex.lVal=1;
varVal.vt=VT_BSTR;
varVal.bstrVal=m_strDlgTitle.AllocSysString();
m_pRs->Fields->GetItem(varIndex)->PutValue(varVal);
varIndex.lVal=2;
::SysFreeString(varVal.bstrVal);
varVal.bstrVal=m_strDlgDescription.AllocSysString();
m_pRs->Fields->GetItem(&varIndex)->PutValue(&varVal);
::SysFreeString(varVal.bstrVal);
vtMissing;
m_pRs->Update(vtMissing,vtMissing);
RefreshBoundData();
}
catch(_com_error &e)
{
AfxMessageBox(e.Description());
}
::SysFreeString(varVal.bstrVal);
the code works fine (the new data shows up in the access DB)
the problem is :
when i call RefreshBoundData the dialog refreshes only the textox that shows the ID (autonumber) while other fields (text,memo) appear empty ..
the code of RefreshBoundData is :
void CRsCgDlgCat::RefreshBoundData()
{
if (adFldOK == lIDStatus)
m_lDlgID = m_lID;
else
m_lDlgID = 0;
if (adFldOK == lTitleStatus)
m_strDlgTitle = m_wszTitle;
else
m_strDlgTitle = _T("");
if (adFldOK == lDescriptionStatus)
m_strDlgDescription = m_wszDescription;
else
m_strDlgDescription = _T("");
UpdateData(FALSE);
}
i found that the problem is : lTitleStatus,lDescriptionStatus are equal to 3 (means that they are nulls !!!)
can u help ?
please send any Qs if my post is not clear
|
|
|
|
|
I'm making a program that sorts fractions, but when I run my program my sort_ratios function is never called. What gives? I'm using c++ on windows xp if that helps.
TIA
Code:
<br />
#include <stdio.h><br />
#include <stdlib.h><br />
#include <math.h><br />
#include <ctype.h><br />
#include <string.h><br />
<br />
typedef int ratio;<br />
ratio num[100][2];<br />
int ct;<br />
<br />
void get_ratios();<br />
void sort_ratios();<br />
int cmp(ratio *, ratio *);<br />
void swap(ratio *, ratio *);<br />
void print_ratios();<br />
<br />
int main()<br />
{<br />
get_ratios();<br />
sort_ratios();<br />
print_ratios();<br />
return 0;<br />
}<br />
<br />
void get_ratios()<br />
{<br />
for(ct = 0;scanf("%d /%d", &num[ct][0], &num[ct][1])!=EOF<code> ;++ct);
}
void sort_ratios()
{
int i, j;
printf("sort ok");
for(i=0;i<ct-1;++i)
for(j=i+1;j>0 && cmp(num[j-1], num[j])>0;--j)
swap(num[j-1], num[j]);
}
int cmp(ratio a[], ratio b[])
{
return a[0]*b[1]-a[1]*b[0];
}
void swap(ratio a[], ratio b[])
{
int temp;
temp=a[0];
a[0]=b[0];
b[0]=temp;
}
void print_ratios()
{
int i;
for(i=0; i<ct; ++i){
printf("%d="" %d="" ",="" num[i][0],="" num[i][1]);
if(i="=12)
putchar('\n');
}
}
</code">
|
|
|
|
|
Is scanf supposed to be fscanf perhaps?
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'm trying to convert this VB line
Dim hWndp As Long<br />
hWndp = WindowFromPoint(Pt.X - 5, Pt.Y - 5)
into C++... any help please?
Thanks,
Mike
|
|
|
|
|
MSDN:
static CWnd* PASCAL WindowFromPoint( POINT point );
So your C++ code should be:
CWnd* hWndp = WindowFromPoint( CPoint(Pt.x - 5, Pt.y - 5) );
|
|
|
|
|
POINT Pt;
HWND hWndp;
POINT Pt2 = Pt;
Pt2.x -= 5;
Pt2.y -= 5;
hWndp = WindowFromPoint ( Pt2 );
--Mike--
Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber
There is a saying in statistics that a million monkeys pounding on typewriters would eventually create a work of Shakespeare. Thanks to the Internet, we now know that this is not true.
|
|
|
|
|
The first time i call EncryptString (below) I pass "<password>asdf" it encrypts to to be a length of 25 and encrypts it right. But when i try to encrypt a 2539 length string it returns a string of a length of 225 and only partically encrypted. Why is this happening and how do I fix it?
CString CEncyptionClass::EncryptString(CString m_strUnencryptedString)
{
//variables
//Date:11 22 03
CString m_strResultingText;
HCRYPTPROV hProv = NULL;
HCRYPTKEY hKey = NULL;
HCRYPTHASH hHash = NULL;
DWORD dwLength;
BYTE * pbBuffer;
LPTSTR m_tContents=ConvertCStringToChar(m_strUnencryptedString);
TCHAR szLocalPassword[] = _T("alongrandompassword");
//
// Get handle to user default provider.
if (CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, 0))
{
// Create hash object.
if (CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash))
{
// Hash password string.
dwLength = _tcslen(szLocalPassword);
if (CryptHashData(hHash, (BYTE *)szLocalPassword, dwLength, 0))
{
// Create block cipher session key based on hash of the password.
if (CryptDeriveKey(hProv, CALG_RC4, hHash, CRYPT_EXPORTABLE, &hKey))
{
dwLength= _tcslen(m_tContents);
pbBuffer=(BYTE*)malloc(dwLength);
if (pbBuffer != NULL)
{
memcpy(pbBuffer, m_tContents, dwLength);
if (CryptEncrypt(hKey, 0, true, 0, pbBuffer, &dwLength, dwLength))
{
m_strResultingText.Format("%s",pbBuffer);
CString strShow;
strShow.Format("After: %s \r\n(%s)\r\n %d %d", m_strResultingText,m_tContents,strlen((const char*) pbBuffer) ,dwLength);
MessageBox(strShow);
}
free(pbBuffer);
}
CryptDestroyKey(hKey); // Release provider handle.
}
}
CryptDestroyHash(hHash); // Destroy session key.
}
CryptReleaseContext(hProv, 0);
}
return m_strResultingText;
}
-Steven Hicks
CPACodeProjectAddict
|
|
|
|
|
I am tring to build a keyboard hook that blocks the
windows keys. It has to be in a seperate dll. The
call to SetWindowsHookEx requires a HINSTANCE to the
dll. How do I get an HINSTANCE to my dll with out
having to use CWinApp. There is way more stuff in the
CWinApp class than I would like to use.
class CTaskKeyHookDll : public CWinApp
{
public :
CTaskKeyHookDll(){ }
~CTaskKeyHookDll(){ }
} MyDll;
class CTaskKeyHookDll
{
public :
HINSTANCE hInstance;
CTaskKeyHookDll(){ }
~CTaskKeyHookDll(){ }
} MyDll;
Anyone know how to do this?
Thank You
Bo Hunter
|
|
|
|
|
in your overridden DllMain() save the first parameter(HINSTANCE) to g_hInstance.
|
|
|
|