|
Hi all,
I stumbled upon an interesting character in a csv file created by Excel. the character's decimal representation is -96 and hex is FFFFFFA0. Does anybone know from which character set this one jumped out?
Thanks in advance.
Alberto Gattegno
Software Engineer
http://www.itgil.com
|
|
|
|
|
Could it be á, i.e 0xA0 or 0xFF - 0xA0, 0c5F '_'
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|
|
Hi
I've always read that with every "new" there shld be a "delete" and likewise with "malloc" and "free", otherwise it'll lead to memory leak.However when the application is terminated, will this resources be freed?
Once, i've created an object with "new" in a loop and was unable to delete the object outside the loop.Anyone knows why?
thks!
|
|
|
|
|
raner wrote:
However when the application is terminated, will this resources be freed?
Yes. In debug mode, the IDE shows nasty comments about the leaks, but thats it.
So, if your app starts, runs a second, leaking a few KB of memory and terminates, no harm is done.
But if you imagine MS-Word would leak one byte per keystroke, you see how this would lead to trouble.
Basically, dont leak at all! It is not that hard to acomplish if you are careful:
Drop char* in favor of std::string or CString, drop dynamic C-arrays in vavor of std::vector etc.
Those pointers that you need are initialised at creation, checked against NULL before use and set to NULL after the delete.
raner wrote:
Once, i've created an object with "new" in a loop and was unable to delete the object outside the loop.Anyone knows why?
You threw away the pointer to this object, eg. overwriting it in the next loop iteration?
Remember: My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
jhwurmbach wrote:
Drop char* in favor of std::string or CString, drop dynamic C-arrays in vavor of std::vector etc.
By std::vector, are u referring to STL?..Sorry i'm not very familiar with VC yet.
For the use of "new" in the loop, yes, i reassigned the pointer to consecutive elements in an array at each iteration.Do i not need to delete the pointer then?
thks alot!
|
|
|
|
|
Yes std:: is the namespace where the STL resides.
Read the tutorials here at CP, and you will understand how it works, and soon be a follower of the GREAT STL *manic laugh*
As to the loop, you said you could not delete memory you new ed in a loop.
If you have overwritten the pointer to this memory (being your only access) in the next iteration, you can not delete it: A delete on your pointer deletes only the last new ed memory.
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
ok..i see the point now.
But can i confirm that the following statements should be fine?
int* pi = 0;
for(int i = 0; i < 100;++i)
{
pi = new int;
//I'll store pointer pi of each iterationin some kind of array, so it can be retrieved later
}
delete pi;
|
|
|
|
|
raner wrote:
But can i confirm that the following statements should be fine?
[..example deleted..]
No! You have 100 'new int ' instructions (in the loop), but only one delete (after the loop). You are leaking 99 int s.
This one works:
#include < iostream >
#define num 100
int main(int argc, char* argv[])
{
typedef int* intPtr;
intPtr* pI = new intPtr[num];
for(int i = 0; i < num; ++i)
{
pI[i] = new int;
*pI[i] = i*i;
}
for( i = 0; i < num; ++i)
std::cout << "i: " << i << " i quadrat: " << *pI[i] << std::endl;
for(i = 0; i < num; ++i)
{
delete pI[i];
}
delete[] pI;
return 0;
}
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
i think i get it...thks alot!
|
|
|
|
|
The best way to understand the difference is to analyze what new/delete is actually doing.
new(global new operator):
1. Call operator new of the data type to allocate n bytes of memory. Default implementation just calls ::malloc(n)
2. Call constructor of the given data type for the new object
delete (global delete operator):
1. Call destructor of the given data type for the object being deleted
2. Call operator delete of the data type to free the memory. The default implementation just calls ::free(p).
Example
main()
{
A* pA = new A();//1. call ::new
//2. call A::operator new(...)
//3. call A::A()
delete pA; ;//1. call ::delete
//2. call A::~A
//3. call A::operator delete(...)
}
The array and build in types are slightly different, but we can ignore the difference for now.
Now about loop allocation
int* pi = 0;
for(int i = 0; i < 100;++i)
{
pi = new int;//we allocate new int
//if we do not call delete before next iteration
//we are going to loose memory when pi is
//reassign to new value
}
I hope it helps
AlexO
P.S. I did not cover constructor/destructor invokation order, I assume you already know about that
|
|
|
|
|
The following example inserts a text (L"Los Angeles") into the bookmark "[City]" in the word.
please, how to pass the text with CString variable instead of (L"text"). That is I need to insert a variable
and please, How to call a "SaveAs" command of the MSWord.
thanx.
void CWordAutoView::OnWordautomation()
{
if (!AfxOleInit())
{
AfxMessageBox("Could not Create an Automation");
return;
}
VARIANT root[64] = {0}; // Generic IDispatchs
VARIANT parm[64] = {0}; // Generic Parameters
VARIANT rVal = {0}; // Temporary result holder
int level=0; // Current index into root[]
// Initialize the OLE Library...
OleInitialize(NULL);
// 1:
VARIANT Sub = {0};
VariantCopy(&Sub, &rVal);
// 2:
VARIANT wordApp = {0};
// 3:
VARIANT wordDoc = {0};
// 4:
VARIANT wordRange = {0};
// 5:
{
CLSID clsid;
CLSIDFromProgID(L"Word.Application", &clsid);
HRESULT hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER|CLSCTX_INPROC_SERVER, IID_IDispatch, (void **)&rVal.pdispVal);
if(FAILED(hr)) {
char buf[256];
sprintf(buf, "CoCreateInstance() for \"Word.Application\" failed. Err=%08lx", hr);
::MessageBox(NULL, buf, "Error", 0x10010);
_exit(0);
}
rVal.vt = VT_DISPATCH;
}
VariantCopy(&wordApp, &rVal);
VariantClear(&rVal);
// 6: Open D:\\Wordtest.doc
VariantCopy(&root[++level], &wordApp);
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &root[level+1], root[level++].pdispVal, L"Documents", 0);
parm[0].vt = VT_BSTR; parm[0].bstrVal = ::SysAllocString(L"D:\\Wordtest.doc");
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &rVal, root[level].pdispVal, L"Open", 1, parm[0]);
VariantClear(&parm[0]);
VariantClear(&root[level--]);
VariantClear(&root[level--]);
VariantCopy(&wordDoc, &rVal);
VariantClear(&rVal);
// 7:
rVal.vt = VT_I4;
rVal.lVal = 1;
VariantCopy(&root[++level], &wordApp);
AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal, L"Visible", 1, rVal);
VariantClear(&root[level--]);
VariantClear(&rVal);
// 8:
VariantCopy(&root[++level], &wordDoc);
AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &rVal, root[level].pdispVal, L"Goto", 1, parm[0]);
VariantClear(&parm[0]);
VariantClear(&root[level--]);
VariantCopy(&wordRange, &rVal);
VariantClear(&rVal);
// 9:
CString city;
city = "MyCity";
VariantCopy(&root[++level], &wordRange);
parm[0].vt = VT_BSTR; parm[0].bstrVal = ::SysAllocString(L"LOS Angeles");
AutoWrap(DISPATCH_METHOD, NULL, root[level].pdispVal, L"InsertAfter", 1, parm[0]);
VariantClear(&parm[0]);
VariantClear(&root[level--]);
// 10: Save
VariantCopy(&root[++level], &wordDoc);
AutoWrap(DISPATCH_METHOD, NULL, root[level].pdispVal, L"SaveAs", 0);
VariantClear(&root[level--]);
// 11:
VariantClear(&wordApp);
// 12:
// Clearing variables
VariantClear(&Sub);
VariantClear(&wordApp);
VariantClear(&wordDoc);
VariantClear(&wordRange);
// Close the OLE Library...
OleUninitialize();
}
|
|
|
|
|
You could use the string conversion macro T2W which converts an LPTSTR to a LPWSTR.
Remember to specify the USES_CONVERSION macro at the start of your function.
For example:
void func( LPTSTR lpsz )
{
USES_CONVERSION;
...
LPWSTR x = T2W(lpsz)
// Do something with x
...
}
|
|
|
|
|
I want to develop a firewall but I want to block packets on the base of MAC address. The problem is when I capture a packet on network layer using winsock the MAC address is already stripped off. We can use ARP but it will increase the network traffic and would be difficult to handle. Plz if u have other options tell me or make the use of ARP clear to me as I am a beginner. Refer me relevent sites/links/libraries/api's e.t.c.
Reply me soon
|
|
|
|
|
If you want to firewall at the network level you can't do it through Winsock. Winsock is to high on the stack to be useful as the etherframes are stripped before you get it, and you should move down to the TDI or NDIS layer in kernel mode. There are plenty of examples for this, and the latest XP SP1 DDK has an example of such a driver. You could modify it to suit (as I don't believe it actually touches the MAC).
As a starting point, try going to: http://www.ndis.com/papers/winpktfilter.htm
It is my understanding that PCAUSA provides a lot of infrastructure and documentation on their own NDIS driver source code which you can purchase. You can start reading about it over here: http://www.rawether.net/ndisim/
Have fun,
SilverStr
|
|
|
|
|
dear all,
i get an error in msdev.exe whenever i try to debug my code in windows xp or win 2K.
but i am able to debug in win 98 and win me.
is there some other way for debugging in windows Xp, 2k and NT.
plz. help!
<marquee width="150">rishabhs
|
|
|
|
|
Hi all...
i have one file *.pck file....as what i know this is the compression image file...how i want to uncompress this file to the valid omage file such as *.jpeg or *.bmp file....
Rgds
;);P ((
:_Rocket_:
|
|
|
|
|
I don't know but the smileys are obviously working just fine.
Or are you somewhat emotionally unbalanced today?
he he he. I like it in the kitchen! - Marc Clifton (on taking the heat when being flamed)
Awasu v0.4a[^]: A free RSS reader with support for Code Project.
|
|
|
|
|
PCK, are you sure? if it is PCT or PCX try the excellent freeware conversion prog from:-
http://www.xnview.com or http://perso.wanadoo.fr/pierre.g
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|
|
What I want
(1)I create a modeless dialog like the following code. See, MainWndProc triggers a modeless dialog "Data", and "Data" triggers another and destroy itself...
Main->Data->Intro->Exper
(2)I want response to key 'A' always to be processed in the dialog function "Parameter_Window_Exper".
What it does now
(1). "Intro" can't be displayed. Why?
(2). 'A' is taken care by MainWndProc still when "Data" has been triggered.
LRESULT CALLBACK MainWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
case WM_CREATE:
hwnddlg = CreateDialog(app_instance, "PARAMETER_WINDOW_DATA", hwnd, (DLGPROC) Parameter_Window_Data);
break;
case WM_CHAR:
switch(wParam) {
case 'A':
MessageBox(hwnd, "top box","response A", MB_OK);//for temporary test
break;
...
}
BOOL CALLBACK Parameter_Window_Data(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
case IDC_OK:
hwnddlg = CreateDialog(app_instance, EXPER_INTRO_DIALOG, hWnd, (DLGPROC) Parameter_Window_Intro_Func);
DestroyWindow(hWnd);
....
}
BOOL Parameter_Window_Intro(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
case IDC_TRAIN_DONE:
DestroyWindow(hWnd);
hwnddlg = CreateDialog(app_instance, "EURO_PAIR", hWnd, (DLGPROC) Parameter_Window_Exper);
}
BOOL CALLBACK Parameter_Window_Exper(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
case WM_CHAR:
switch(char(wParam))
{
case 'A':
MessageBox(hWnd, "dialog box", "correct A response", MB_OK);
break;
}
....
}
|
|
|
|
|
"Intro" can't be displayed. Why?
"Intro" is created as a child of "Data", so it gets destroyed along with it. Make it a child of "Main", this should fix the problem.
(2). 'A' is taken care by MainWndProc still when "Data" has been triggered.
Not sure what's going on here. Does "Data" have the focus when you press the key?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Anonymous wrote:
'A' is taken care by MainWndProc still when "Data" has been triggered
You have to use IsDialogMessage instead of DispatchMessage .
rechi
|
|
|
|
|
so you mean I should do this? But it seems that the key can't get response from the dialog still.
extern HWND hwnddlg;
int APIENTRY WinMain(HINSTANCE hCurrentInst, HINSTANCE hPreviousInst, LPSTR lpszCmdLine, int nCmdShow)
{
...
while (GetMessage(&msg, NULL, 0, 0)) {
//TranslateMessage(&msg);
IsDialogMessage(hwnddlg,&msg);
//DispatchMessage(&msg);
}
return (msg.wParam);
}
|
|
|
|
|
You are right, it's not enough; the 'A' is stolen by the control that actually has the focus in the dialog box.
You could fix it by subclassing the controls able to gain the focus or you could create a hidden button with 'A' as mnemonic key.
rechi
|
|
|
|
|
"Hidden button with 'A' as mnemonic key": So clever an solution!!
so by "mnemonic" you mean that I should define a so-called "acceleration key"?
But how to define acceleration key to a button in a dialog? can you explain more? I only know the acceleration key to a menu in the main window--a newbie of windows programming.
Thank you.
|
|
|
|
|
Just type & before the key you want to use as mnemonic for that button.
For example: Butt& on will have the o key as mnemonic.
rechi
|
|
|
|
|