|
Thanks for your reply!
To be more precise, i only get the error when i am exiting the main application. My project is a SDI project. When i compile and link in Release mode, there's no problem at all. From what i understand about MFC, when we use the keyword new for allocation purposes, we should use delete in conjunction with it right?
i only used new when i am initializing my form view.i use a pictutre control to reserve a place on my form view for my property sheet(ie. a place holder). my code goes like this:
/********************************************************/
// create and associate the property sheet with
//the "place holder" window
/********************************************************/
CMySheet *pMySheet;<br />
<br />
CWnd* pPlaceHolder = GetDlgItem(IDC_PLACEHOLDER);<br />
<br />
pMySheet = new CMySheet(pPlaceHolder);<br />
<br />
if (!pMySheet->Create(pPlaceHolder, WS_CHILD | WS_VISIBLE, 0))<br />
{<br />
delete pMySheet;<br />
pMySheet = NULL;<br />
return;<br />
}
// fit the property sheet into the place holder window
// and show it
CRect m_PlaceSheet;<br />
<br />
GetDlgItem( IDC_PLACEHOLDER )->GetWindowRect( &m_PlaceSheet );<br />
<br />
ScreenToClient( &m_PlaceSheet );<br />
<br />
pMySheet->SetWindowPos( NULL, 0, 0, m_PlaceSheet.Width(), m_PlaceSheet.Height(), SWP_NOZORDER | SWP_NOACTIVATE );
Thanks for any help in advance!!
|
|
|
|
|
Are you Attach ing another CWnd-based object to one of your windows controls?
The reason it works in release mode is likely not because the error/problem goes away, it is because there is no diagnostic code to report on it. There are very few errors that are a true result of the Debug mode of the Compiler/Linker.
The only thing that jumps out at me is that you are allocating into pMySheet , which is a local variable. That means that you are either really leaking it, or deleting it later in the same function, when it looks like the CMySheet object is supposed to have a longer lifetime. Either way, it looks like that pointer is being mismanaged.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites
|
|
|
|
|
Hi,
I am trying to insert items in VB List View control from VC++ dll using SendMessage API. its in the same process and even the handle of list view is proper. I am using this code.. but it does not insert the item ...
TCHAR msgString[512];
TCHAR tempString[128];
wsprintf(tempString, _TEXT(" MsgId: %03d "), message->buffer[8] );
_tcscpy(msgString, tempString );
_tcscat(msgString, _T("sadsadsdsad "));
LVITEMW LvItem;
LvItem.mask=LVIF_TEXT; // Text Style
LvItem.cchTextMax = 256; // Max size of test
LvItem.iItem=0; // choose item
LvItem.iSubItem=0; // Put in first coluom
LvItem.pszText=msgString; // Text to display (can be from a char variable) (Items)
SendMessage(hwndMsgRqst,LVM_INSERTITEM,0,(LPARAM)&LvItem); // Send info to the Listview
I am able to get the item count using LVM_GETITEMCOUNT
Any help is really appreciated
Jaffar
|
|
|
|
|
I don’t know how much this will help or not but here is how I accomplished a similar task with a list box. This is a snippet of the real code, just for example sake.
<br />
CPP<br />
#define AddListText(hwnd, txt) \<br />
( int )SendMessage( ( hwnd ), LB_ADDSTRING, 0, ( LPARAM ) (LPCTSTR) txt)<br />
<br />
<br />
void AddListString(long lhwnd, LPCTSTR sAdd)<br />
{<br />
HWND hwnd = (HWND) lhwnd;<br />
AddListText (hwnd, sAdd);<br />
}<br />
<br />
VB<br />
Private Declare Sub AddListString Lib "SCC_DLL.dll" (ByVal lhwnd As Long, ByVal sAdd As String)<br />
<br />
Private Sub cmdAddString_Click()<br />
Dim sText As String<br />
sText = "Text"<br />
AddListString List1.hWnd, sText<br />
End Sub<br />
In a few hours I will be in front of my workstation and be able to try something similar with a list view if yea like.
Mohamed Jaffar Sagir wrote:
Hi,
I am trying to insert items in VB List View control from VC++ dll using SendMessage API. its in the same process and even the handle of list view is proper. I am using this code.. but it does not insert the item ...
TCHAR msgString[512];
TCHAR tempString[128];
wsprintf(tempString, _TEXT(" MsgId: %03d "), message->buffer[8] );
_tcscpy(msgString, tempString );
_tcscat(msgString, _T("sadsadsdsad "));
LVITEMW LvItem;
LvItem.mask=LVIF_TEXT; // Text Style
LvItem.cchTextMax = 256; // Max size of test
LvItem.iItem=0; // choose item
LvItem.iSubItem=0; // Put in first coluom
LvItem.pszText=msgString; // Text to display (can be from a char variable) (Items)
SendMessage(hwndMsgRqst,LVM_INSERTITEM,0,(LPARAM)&LvItem); // Send info to the Listview
I am able to get the item count using LVM_GETITEMCOUNT
Any help is really appreciated
Social Engineering Specialist.
Because there is no patch for human stupidity.
|
|
|
|
|
Hi thanks for the code...
It works fine if we are sending string or string pointer.
But if we pass structure( in case of list view), it does not work out. could u pls try with listview
|
|
|
|
|
No problem, if you can send me the snippet of code (it will make it easier) that would be great.
I'm no C++ expert / guru. But I do enjoy a challenge.
[edit]
I can’t guarantee I will get to it this weekend (the Girlfriend has barred me from working on the weekends, something about being bored watching me sit in front of the computer for > 12 hrs)
[/edit]
Social Engineering Specialist.
Because there is no patch for human stupidity.
|
|
|
|
|
enjoy the weekend
please find the snippet..
VC++ code:
**************************************************
DLL_EXPORT_VB void __stdcall RegisterLogWindow(HWND hwndMsgLog, HWND hwndMsgRqst )
{
TCHAR msgString[512];
memset(msgString, 0, sizeof (msgString));
SYSTEMTIME st;
GetLocalTime(&st);
wsprintf(tempString, _TEXT(" Dt: %02d:%02d:%04d - %02d:%02d:%02d:%03d "), st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds );
_tcscat(msgString, tempString );
int iItem=SendMessage(hwndMsgRqst,LVM_GETITEMCOUNT,0,0);
//LVITEMW LvItem;
LVITEMW LvItem1;
LvItem1.mask=LVIF_TEXT; // Text Style
LvItem1.cchTextMax = 256; // Max size of test
LvItem1.iItem=iItem ; // choose item
LvItem1.iSubItem=0; // Put in first coluom
LvItem1.pszText= msgString; // Text to display (can be from a char variable) (Items)
int hr = SendMessage(hwndMsgRqst,LVM_INSERTITEM,0,(LPARAM)&LvItem1); // Send info to the Listview
int err = GetLastError() ;
}
**** hr and rr returns 0.... itemcount got is correct
************************************
VB snippet
Declare Function RegisterLogWindow Lib "ToolsEng.dll" (ByVal hLogWindow As Long, ByVal hMsgWindow As Long) As Long
RegisterLogWindow lbEclipseEventLog.hWnd, ListView1.hWnd
|
|
|
|
|
Sorry Mohamed, I was unable to get it fully working as well. I will keep working on it; it’s an interesting idea.
I kept getting access-denied errors from the list view.
Social Engineering Specialist.
Because there is no patch for human stupidity.
|
|
|
|
|
What are the available error codes after the call fails? Both the return code of the call to SendMessage(...) and the value returned by GetLastError() (note that you have to call GetLastError() right after the call to SendMessage(...) ).
BTW: you are taking "the long way around" to build the contents of msgString ...
Peace!
-=- James
Tip for inexperienced drivers: "Professional Driver on Closed Course" does not mean "your Dumb Ass on a Public Road"! Articles -- Products: Delete FXP Files & Check Favorites
|
|
|
|
|
Both SendMessage and GetLastError returns 0..
|
|
|
|
|
If the call returns successful return/error codes, and the Item Count increases after the call, my guess is that you have a redraw problem.
Try forcing a redraw of the application/control and see if your item shows up. Also, make sure that column zero has a real width. With a multi-column ListView control, if Column 0 has a width of zero, newly added items with no subitem text will be effectively invisible.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites
|
|
|
|
|
If i want to do MX query through NSLOOKUP what will be the actual code line for that
Plz Help
ankit
|
|
|
|
|
I Hope this Exact Syntax for NsLookUP
c:\>nsLookUp -type=mx yahoo.com
this will return all the Mail server of Yahoo.com
"I Think this Will Help"
<h5
alok gupta="" <br=""> visit me at http://www.thisisalok.tk
|
|
|
|
|
i just found that it also don't run on windows 98 is there any alternative for it
ankit
|
|
|
|
|
Pls go through this link [^] Seems like can provide a bit of help for your problem.
suhredayan There is no spoon.
|
|
|
|
|
but if i wnt to do text query
then
i was earlier doing it through api DNSQUERY
but that is not supported on windows 98
i want to know version by "current.cvd.clamav.net"
it was sucessful with DNSQUERY(but unsupported on win98)
so is there way to do it
ankit
|
|
|
|
|
Hello All,
I'm unable to use GetIDispatch with ImageList Control (Visual Studio 6.0). I get an error "Invalid Object", what could be the problem
Thanks & Regards
Rajmathi
|
|
|
|
|
I have a printer datafile in a remote computer. I want to print it in my local printer. It's encoded in pcl language, but it's too large to move it into my pc. How can I split large printer data files into multiple pages and print them continuously(one by one)
|
|
|
|
|
Hello
to all of u
i am using api DNSQUERY to get the version of database of main.cvd and daily.cvd files of clamav(antivirus) from current.cvd.clamav.net
i am getting the correct remote version but this api is not supported by windows 98 so please tell me any api or any other way how can i get the result on win 98 also
Thanks in advance
ankit
ankit
|
|
|
|
|
Hi all,
When any document is opened in ms word then it also creates .tmp file in same folder/temp folder. I want to stop such .tmp file creation.
How can i do that ? Can it be done by some option in MSWord settings? can it be done by writting addin DLL for that? or thru can it be done by writing COM,VC++ application ?
Please Let me know if it is possible? how? by which method?
Any suggestion are welcome.
Thank in advance.
Jetli
conclusion means Coming to wrong Decision with confidence
|
|
|
|
|
they're automatic recovery files.
go in the tool\options\file location
and either turn off automatic recovery or point it
to a different folder (it's a good feature, but
you may not want it in with your .doc files
because it crowds your directory
|
|
|
|
|
shaveyourhead wrote:
go in the tool\options\file location
and either turn off automatic recovery or point it
to a different folder
Yes u are right.
But Even if i uncheck those option, word still creates .tmp file.
Does anybody has point to this?
How to prevent word from creating ,tmp file, by any means (COM Addin, programmatically etc...)
Thanks
Jetli
conclusion means Coming to wrong Decision with confidence
|
|
|
|
|
See MSDN article Q211632.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I'm looking for multi-user server source code (tutorial) (C/C++, sockets, no MFC).
Oh, I already know how to do multi connections the windows way (messages sent to my window when data is received), but that's not what I want.
I know there are some here at codeproject but they all use MFC (yuck) and seem alot more complicated then what I've found so far.
I found the original at www.planet-source-code.com (I've re-done and simplified it for this post):
SOCKET ServerSocket;
SOCKADDR_IN server_address;
FD_SET masterSet;
HANDLE ThreadHandle;
DWORD ThreadID;
int RetVal = 0;
DWORD WINAPI acceptingThreadProcedure(LPVOID ServerSocket)
{
SOCKET* Socket = (SOCKET*)ServerSocket;
SOCKET ClientSocket;
while(1)
{
ClientSocket = accept(*Socket,0,0);
FD_SET(ClientSocket,&masterSet);
printf("Client on %d connected\n",ClientSocket);
}
return TRUE;
}
int InitServer()
{
WSADATA wsaData;
WSAStartup(MAKEWORD(1,0),&wsaData);
ServerSocket = socket(PF_INET,SOCK_STREAM,0);
server_address.sin_family = AF_INET;
server_address.sin_port = 4200;
server_address.sin_addr.s_addr = INADDR_ANY;
bind(ServerSocket,(SOCKADDR*)&server_address,sizeof(SOCKADDR_IN));
listen(ServerSocket,5);
ThreadHandle = CreateThread(NULL,0,acceptingThreadProcedure,&ServerSocket,0,&ThreadID);
Sleep(100);
FD_ZERO(&masterSet);
FD_SET pollingSet;
timeval waitTime;
waitTime.tv_sec = 0;
waitTime.tv_usec = 0;
SOCKET clientSocket;
unsigned long BufferSize;
while(1)
{
pollingSet = masterSet;
if(pollingSet.fd_count == 0)
continue;
RetVal = select(pollingSet.fd_count,&pollingSet,NULL,NULL,&waitTime);
if(RetVal == 0)
continue;
for(unsigned int i = 0; i < pollingSet.fd_count; i++)
{
clientSocket = pollingSet.fd_array[i];
recv(clientSocket,(LPSTR)&BufferSize,sizeof(BufferSize),0);
BufferSize = ntohl(BufferSize);
LPSTR Buffer = new char[BufferSize];
recv(clientSocket,(LPSTR)Buffer,BufferSize,0);
Buffer[BufferSize] = '\0';
printf("Client %d: %s\n",clientSocket,Buffer);
delete[] Buffer;
}
}
}
I've been looking for tutorials that teach it with FD_SET and select but havn't found anything yet.
Does anyone know of a good tutorial?
P.S. The reason I'm looking for something more than what I've found is that the current code (above) doesn't have a way to send data back, and I'm not sure how to add that. Also the code just doesn't seem right (tho I don't know what multi-user code looks like), and it uses 100% system resources.
Alright, thank you much.
|
|
|
|
|
Well if you don't like MFC, try this unix sample:
/*
* ClockServer.c
* sample Unix (SCO) clock server for pcsclock
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
/* network includes */
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
/* PCS specific */
#include "token.h"
#include "unixser.h"
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
/* the default port */
int Port = 9999;
// The socket
int Socket;
// The connection the child talks through
int NewConnection;
int SerialPort, Opened;
char Buf[BUFSIZ];
enum tagCOMMANDS
{
UNKNOWN = -1,
wOPEN,
wCLOSE
};
KEYWORDS KeyWords[]=
{
"open", 4,
// PCSClock sends 'CLOSE' just before it does so
"CLOSE", 5,
NULL, 0
};
/*
* Trim a string of spaces (Control characters remain)
*/
char *Trim(char *String)
{
int sLen;
if(String != (char *)NULL)
{
sLen = 0;
while(*(String + sLen) == ' ')
sLen++;
if(sLen)
strcpy(String, String + sLen);
if((sLen = strlen(String)) > 0)
{
while(sLen && *(String + sLen - 1) == ' ')
{
*(String + sLen - 1) = 0;
sLen--;
}
}
}
return(String);
}
int InterpCommand(char *Buf)
{
char *cp = Buf;
char Token[128];
if(GetToken(&cp, Token) != FINISHED)
{
switch(IsReservedVar(Token, KeyWords))
{
case wOPEN:
if(!Opened)
{
fprintf(stderr, "Opening %s\n", cp);
SerialPort = ComOpen(Trim(cp), 256, 256);
if(SerialPort >= 0)
{
if(ComSetParams(SerialPort, 9600, NONE, 8, 1, NONE) == OK)
{
write(NewConnection, "OK", 2);
Opened = TRUE;
}
}
if(!Opened)
{
write(NewConnection, "Fail", 4);
perror("Open port failed");
}
}
break;
case wCLOSE:
if(Opened)
ComClose(SerialPort);
Opened = FALSE;
return(FALSE);
default:
fprintf(stderr, "unknown command %s\n", Buf);
break;
}
}
return(TRUE);
}
int main(int argc, char **argv)
{
struct sockaddr_in Sock_IN;
if(argc == 2)
{
int Tmp;
Tmp = atoi(argv[1]);
if(Tmp > 0)
Port = Tmp;
}
if((Socket = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
perror("socket() failed");
exit(1);
}
memset(&Sock_IN, 0, sizeof(Sock_IN));
Sock_IN.sin_family = AF_INET;
Sock_IN.sin_port = htons(Port);
Sock_IN.sin_addr.s_addr = htonl(INADDR_ANY);
if(bind(Socket, (struct sockaddr *)&Sock_IN, sizeof(Sock_IN)) == -1)
{
perror("bind() failed");
exit(1);
}
if(listen(Socket, 5) == -1)
{
perror("listen() failed");
exit(1);
}
while(TRUE)
{
int Pid;
fprintf(stderr, "Accepting");
if((NewConnection = accept(Socket, 0, 0)) == -1)
{
perror("accept() failed");
exit(1);
}
/* Start a new child */
if((Pid = fork()) == -1)
{
perror("fork() failed");
exit(1);
}
if(Pid == 0)
{
int FirstTime = TRUE;
Opened = FALSE;
SerialPort = -1;
Pid = getpid();
while(TRUE)
{
int Count;
*Buf = 0;
if((Count = read(NewConnection, Buf, sizeof(Buf))) == -1)
{
perror("read() failed");
exit(1);
}
if(!Count)
break;
Buf[Count] = 0;
fprintf(stderr, "%d Read: %s\n", Pid, Buf);
/* Clock commands always begin with '>' */
if(*Buf == '>')
{
if(Opened)
{
clock_t Tick;
char *cp;
char SerBuf[BUFSIZ];
if(write(SerialPort, Buf, Count) < 0)
perror("Write serial port failed");
// Don't know why but on this stupid SCO machine
// the io seems so slow that we now have to wait
// for serial output to complete
sleep(1);
cp = SerBuf;
*cp = 0;
Tick = clock();
while(clock() - Tick < 3000)
{
if(read(SerialPort, cp, 1) == 1)
{
cp++;
*cp = 0;
/* Clock replies always end in <CR> */
if(*(cp - 1) == '\r')
{
Count = strlen(SerBuf);
if(send(NewConnection, SerBuf, Count, 0) != Count)
perror("send failed");
fprintf(stderr, "%d Sending %s\n", Pid, SerBuf);
break;
}
Tick = clock();
}
}
}
else
perror("No open received");
}
else if(*Buf)
if(!InterpCommand(Buf))
break;
}
close(NewConnection);
fprintf(stderr, "%d child dying", Pid);
exit(0);
}
/* Close the parent's connection */
close(NewConnection);
}
}
|
|
|
|
|