|
John R. Shaw wrote: There are still commercial Apps the use MFC and posting for positions requiring it.
I didn't mean to imply that MFC is no longer current, it's just that it is not available with the (free) Express editions of Visual C++.
The best things in life are not things.
|
|
|
|
|
|
How can a program know if "Microsoft Visual C++ 2010 Redistributable Package (x86)" is installed. If possible, provide a sample code.
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
|
Thank you!
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Hello All,
I am using VC++/Com application and working with database.
I am using '_RecordsetPtr' to fetch database tables.
Here 'RsITEM' Macro to get particular column data. Everything works fine unless you encounter with NULL value. If values comes to be NULL, it just throw exception, and application crashes. Not allowing null values in database is not solution in my case.
Any help in this regard is highly appreciated.
Happy Programming.
|
|
|
|
|
You need to check the Item for equality to VT_NULL before calling it's GetValue() method, like this[^].
|
|
|
|
|
Hi this is my code
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
lf.lfHeight = 15;
lf.lfWeight = FW_REGULAR;
m_fontRegular.CreateFontIndirect(&lf);//m_fontRegular is object of CFont
m_ctrlComboBrowsers->SetFont(&m_fontRegular);// m_ctrlComboBrowsers is object of CComboBox
i am adding some string to combobox, problem is in XP machine combobox's dropdown list is not showing....
please help me.
|
|
|
|
|
Have you done the layout of it in the dialog template properly?
In the dialog template, click on the drop down arrow of the combo box and resize the control by expanding it downwards.
|
|
|
|
|
its created dynamically... problem was same what u told, size of the combobox was not expanded size, that was the issue.but my doubt is why this problem is coming only in xp?....
thanks..
|
|
|
|
|
Hi,
Im declaring one char array in dialog Header File.
char *czTagGetVal;
And in one dialog class,im using that array as
void CGraphicsTagDlg:: GetTagLbl(int iLNo)
{
czTagGetVal = new char[50];
memset(czTagGetVal,0,50);
.
.
.
}
After debugging i get the solution without any error.But when i close the applcaition,in Output window i saw lot of Memory leak detection.
So while closing the application i delete this array as
if(czTagGetVal)
delete [] czTagGetVal;
But i get the error as
Windows has triggered a breakpoint in GraphicsTag.exe.
This may be due to a corruption of the heap, which indicates a bug in GraphicsTag.exe or any of the DLLs it has loaded.
How can i avoid this error.I used such kind of array in my applcation by using new operator.I want to delete all allocated memory.How can i do that.Pls help me.
Anu
|
|
|
|
|
You should change:
Anu_Bala wrote: char *czTagGetVal;
to
char *czTagGetVal = NULL;
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Without seeing more of your code i have 2 guesses: you are either writing into memory out of bounds (so e.g. you allocated space for 50 characters but are writing more than that into the buffer, 51 or 100 or... The other guess is, you are trying to free up memory you didn't allocate OR you are trying to free up the same block of memory twice.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
Im getting value by using this code
glg_animation[iPage].viewport.GetResource("\\Tag\\String",&czTagGetVal);
sTagName = (CString)czTagGetVal;
In OnClose(),when i debug this part of code
if(czTagGetVal)
delete [] czTagGetVal
czTagGetVal has value as "ALRMCAB ".So definitely it is less than 50 and also im allocating the memory using new and assign value also.But this error is coming.
I delete this char array at the end of the fucntion where it is actually using.But the same error is coming.
Anu
|
|
|
|
|
Shouldn't this:
Anu_Bala wrote: glg_animation[iPage].viewport.GetResource("\\Tag\\String",&czTagGetVal);
be this:
glg_animation[iPage].viewport.GetResource("\\Tag\\String",czTagGetVal); ?
But if you use this buffer in a function only, then why don't you simply declare it on the stack in the function?
void This_is_the_function()
{
char czTagGetVal[50];
...
}
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
Actaully that GetResource() is third party fucntion(using DLL) and then GetResourceis decalred as
GetResource( char * res_name, char ** s_value );
So i have to use that.
Anu
|
|
|
|
|
That suggests that the function will allocate the string for you, so you don't need to do it, probably just free it (of course that depends on that 3rd party library). So like this:
void this_is_the_function(...)
{
char *czTagGetVal = NULL;
glg_animation[iPage].viewport.GetResource("\\Tag\\String",&czTagGetVal);
sTagName = (CString)czTagGetVal;
...
}
Be careful with freeing up memory allocated by 3rd party things because if you don't do the de-allocation that is in pair with the allocation you can get unpredictable results.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
Judging by that function signature, GetResource will either allocate a string for you, or return a pointer to a string it stores internally (or statically). In either case, the pointer you pass will be overwritten, and any memory previously allocated that this pointer used to point to will be lost!
So, what you should do is:
1. do not allocate memory yourself!
2. initialize the pointer with NULL instead, before calling GetResource()
3. Check the documentation of GetResource() whether or not it allocates memory that needs to be freed or not. If your delete causes an error, then most likely it shouldn't be deleted, or it already gets deleted by whoever manages these resources.
|
|
|
|
|
Possibilities for Error:
- You've already deallocated this memory block.
- If you allocated within a DLL, you should deallocate within the same DLL. Don't do memory management across DLL boundaries.
Memory Leak:
- If the function GetTagLbl() gets called more than once, you'll have leaking memory by only deleting once when closing.
|
|
|
|
|
Hi all,
i am using CreateFile to open the port,its working fine when i am handle this with only single port.
but now i want to open multiple port at the same time and perform read/write operation on these ports.
In The open port method, it opens the first available port and when it gets the second it closes the opened one and then opens the next port and so on.
if (IsOpen())
{
BOOL bSuccess = CloseHandle(m_hComm);
m_hComm = INVALID_HANDLE_VALUE;
if (!bSuccess)
TRACE(_T("Failed to close up the comms port, GetLastError:%d\n"), GetLastError());
}
if (m_hEvent)
{
CloseHandle(m_hEvent);
m_hEvent = NULL;
}
CString sPort;
sPort.Format(_T("\\\\.\\COM%d"), nPort);
m_hComm = CreateFile(sPort, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
so please help me how can i do this.
thanks in advance.
|
|
|
|
|
Are you possibly using the same instance of this class to open all your ports?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
i am using it like this:
void CAppClass::fun1()
{
for(int i=0; i<port_count;i++)
{
CPort_Class* p_c=new CPort_Class;
p_c->Open()
p_c->Close();
}
}
|
|
|
|
|
This code opens a port and then later on closes it before going on with the next one. I thought you wanted to have multiple ports open at the same time. Could you clearify?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
yes i want to open the multiple port at same time.
|
|
|
|
|
The code fragment you have shown opens and closes the ports one-by-one. You should rethink your strategy i guess. Without knowing more about what exactly you are trying to achieve it is hard to guess on anything, but you could for example try strating a new thread for each port if there aren't too many ports you want to use (of course you would need to implement proper synchronization as needed), or you could have an array for the port class instances, something like this:
CPort_Class *ports = new CPort_Class[portcount]
for (int port = 0; port < portcount; port++) ports[port].Open();
...
...
for (int port = 0; port < portcount; port++) ports[port].Close();
delete []ports; This is a simplified code fragment, you would of course need to do error checks too.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|