|
I have written an TDI server program, which is not able to accept any connection although listen succeeds. Given below my sample code. Please help me in figuring out where i am wrong or if possible suggest me for some good source link.
NTSTATUS
Listen(PFILE_OBJECT FileObject) //UINT Addr
{
NTSTATUS Status = STATUS_INSUFFICIENT_RESOURCES;
PIRP Irp;
IO_STATUS_BLOCK IoStatus = {0};
PDEVICE_OBJECT DeviceObject;
char cBuffer[256] = {0};
char ack[20] = "ok";
PTRANSPORT_ADDRESS pTransportAddress = (PTRANSPORT_ADDRESS)&cBuffer;
TDI_CONNECTION_INFORMATION RequestConnectionInfo = {0};
TDI_CONNECTION_INFORMATION ReturnConnectionInfo = {0};
KEVENT Event;
DbgPrint("Inside listen");
KeInitializeEvent(&Event, NotificationEvent, FALSE);
DeviceObject = IoGetRelatedDeviceObject(FileObject);
Irp = TdiBuildInternalDeviceControlIrp(TDI_LISTEN, DeviceObject, FileObject,
&Event, &IoStatus);
if (Irp == 0)
{
DbgPrint("TDI_LISTEN .... failed\n");
return STATUS_INSUFFICIENT_RESOURCES;
}
DbgPrint("TdiBuildInternalDeviceControl success");
RequestConnectionInfo.UserData = (PVOID) ack;
RequestConnectionInfo.UserDataLength = strlen(ack);
RequestConnectionInfo.Options = 0; //TDI_QUERY_ACCEPT;
RequestConnectionInfo.OptionsLength = sizeof(ULONG);
RequestConnectionInfo.RemoteAddress = NULL;
RequestConnectionInfo.RemoteAddressLength = 0;
DbgPrint("Before Delay");
delay(30);
TdiBuildListen(Irp, DeviceObject, FileObject, NULL, NULL, 0, &RequestConnectionInfo, &ReturnConnectionInfo);
DbgPrint("After TdiBuildListen");
Status = IoCallDriver(DeviceObject, Irp);
if (Status == STATUS_PENDING)
Status = KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL); //UserMode
DbgPrint("Leaving TdiBuildListen");
return Status == STATUS_SUCCESS ? IoStatus.Status : Status;
}
/*
* accept
*/
NTSTATUS
Accept(PFILE_OBJECT FileObject)
{
/*
TA_IP_ADDRESS taIpAddress;
TDI_CONNECTION_INFORMATION tdiConnectionInformation;
RtlZeroMemory( &taIpAddress, sizeof( taIpAddress ) );
taIpAddress.TAAddressCount = 1;
taIpAddress.Address[ 0 ].AddressLength = TDI_ADDRESS_LENGTH_IP;
taIpAddress.Address[ 0 ].AddressType = TDI_ADDRESS_TYPE_IP;
RtlZeroMemory( &tdiConnectionInformation, sizeof( tdiConnectionInformation ));
tdiConnectionInformation.RemoteAddressLength = sizeof( taIpAddress );
tdiConnectionInformation.RemoteAddress = &taIpAddress;
*/
NTSTATUS Status = STATUS_INSUFFICIENT_RESOURCES;
PIRP Irp;
IO_STATUS_BLOCK IoStatus = {0};
PDEVICE_OBJECT DeviceObject;
char cBuffer[256] = {0};
PTDI_ADDRESS_IP pTdiAddressIp;
PTRANSPORT_ADDRESS pTransportAddress = (PTRANSPORT_ADDRESS)&cBuffer;
TDI_CONNECTION_INFORMATION RequestConnectionInfo = {0};
TDI_CONNECTION_INFORMATION ReturnConnectionInfo = {0};
KEVENT Event;
KeInitializeEvent(&Event, NotificationEvent, FALSE);
DeviceObject = IoGetRelatedDeviceObject(FileObject);
DbgPrint("Inside Accept");
DbgPrint("Before TdiBuildInternalDeviceControlIrp");
delay(25);
Irp = TdiBuildInternalDeviceControlIrp(TDI_ACCEPT, DeviceObject, FileObject,
&Event, &IoStatus);
if (Irp == 0)
{
DbgPrint("Failure in TdiBuildInternalDeviceControlIrp");
return STATUS_INSUFFICIENT_RESOURCES;
}
DbgPrint("After TdiBuildInternalDeviceControlIrp");
pTransportAddress->TAAddressCount = 1;
pTransportAddress->Address[0].AddressType = TDI_ADDRESS_TYPE_IP;
pTransportAddress->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP;
pTdiAddressIp = (TDI_ADDRESS_IP *)&pTransportAddress->Address[0].Address;
pTdiAddressIp->sin_port = HTONS(PORT); //* Example: 1494 = 0x05D6 (Little Endian) or 0xD605 (Big Endian)
pTdiAddressIp->in_addr = INETADDR(10,6,21,20); //* Example: 10.60.2.159 = 0A.3C.02.9F (Little Endian) or 9F.02.3C.0A (Big Endian)
RequestConnectionInfo.UserData = NULL;
RequestConnectionInfo.UserDataLength = 0;
RequestConnectionInfo.Options = 0;
RequestConnectionInfo.OptionsLength = 0;
RequestConnectionInfo.RemoteAddress =(PVOID)pTransportAddress;
RequestConnectionInfo.RemoteAddressLength = sizeof(PTRANSPORT_ADDRESS) + sizeof(TDI_ADDRESS_IP);
DbgPrint("Before TdiBuildAccept");
delay(25);
TdiBuildAccept(Irp, DeviceObject, FileObject, NULL, NULL, &RequestConnectionInfo, &ReturnConnectionInfo);
DbgPrint("After TdiBuildAccept");
delay(25);
Status = IoCallDriver(DeviceObject, Irp);
if (Status == STATUS_PENDING)
Status = KeWaitForSingleObject(&Event, UserRequest, KernelMode, FALSE, 0);
DbgPrint("Leaving Accept");
delay(25);
return Status == STATUS_SUCCESS ? IoStatus.Status : Status;
}
With thanks in advance,
barun
barun
|
|
|
|
|
Hi All,
I am using listctrl in which I add JPEG images loading from images saves on hard disk.
To Set item in ListCtrl control I use SetItem() function as follows
CString pstr = "C:\\JPEG_image";
BOOL blnCheck = mWebPagePrvListCtrl.SetItemData(iItemindex,(DWORD)pstr);
But the above statement not set the value of pstr in ListCtrl.
To identify which images is click by user I use following code to access data of image.
as
int itemIndex = mWebPagePrvListCtrl.GetHotItem();
CString* pStr = (CString*) mWebPagePrvListCtrl.GetItemData(itemIndex);
Plz send me what is the problem in above code.
Thanks in Advance
Atul
|
|
|
|
|
CString pstr = "C:\\JPEG_image";
It is local, right?
- NS -
|
|
|
|
|
|
Atulmahajan wrote: Yes It is Local.
So I think you are mistaken.
Actually you are trying to save the image name along with each list control item, right? SetItemData is holding only a 4 byte value. We are using this to hold a pointer. Here in your case, it is a pointer to the string. Since the string is local when you exit from the function, the pointer will not be valid. So the stored pointer has no use.
One solution is that you can dynamically allocate the string in heap (using new CString). But need to delete the memory when you close the window, or delete the list control item.
Another method is that you can use a CStringArray object as member variable. Then you can store each string in the array and can keep the index in the list control item data. Here also removal of the string item from the array is needed, if you delete a list control item (just for saving the memory).
Hope you got the idea.
- NS -
|
|
|
|
|
How to import dll in to my vc++ 8.0 programme
I want to include the “dwlGina2.dll” in to my programme and to call all the function in the dll, iam new to dll,
so explain me briefly
regards
shakumar
shakumar
|
|
|
|
|
along with that dll, you should also have the corresponding .lib and .h.
do you have?
|
|
|
|
|
no
There is no .cpp ,.h file in the name of dll of file
shakumar
|
|
|
|
|
You can use of dll with load it on your program.
|
|
|
|
|
Hi all,
How can i know that the user has pressed ALT+F4 key combination .
Thanks in advance.
|
|
|
|
|
Hi,
for example in PreTranslateMessage :
if (msg->message == WM_KEYDOWN)
{
if(msg->wParam == VK_F4 && GetKeyState(VK_LMENU)<0)
{
}
}
I hope it works
|
|
|
|
|
baerten wrote: if(msg->wParam == VK_F4 && GetKeyState(VK_LMENU)<0)
You want it to work only if the Left Alt is pressed? I would rather suggest VK_MENU instead of VK_LMENU . Moreover, I doubt if this would ever work!
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->ßRÅhmmÃ<-·´¯`·.
|
|
|
|
|
Hi,
Its working. Thanks for ur reply
|
|
|
|
|
Handle WM_CLOSE and place the following code in it:
if(GetKeyState(VK_MENU)<0 && GetKeyState(VK_F4)<0)
{
AfxMessageBox("Alt and F4 keys are down!");
}
[I am assuming that you're working on a dialog based app and using MFC. Do reply if there's something different]
|
|
|
|
|
Hello everyone,
If I am developing a native unmanaged COM using Visual Studio 2005 C++, is it a mandatory to register type lib into HKEY_CLASSES_ROOT\TypeLib?
I have already registered related entries into HKEY_CLASSES_ROOT\CLSID\<co clas="" id="">, HKEY_CLASSES_ROOT\Interface\<interface id="" of="" co="" class="" exposed=""> and HKEY_CLASSES_ROOT\<co class="" name="">.
What is the function of the entry under HKEY_CLASSES_ROOT\TypeLib during COM object discovery and creation process?
thanks in advance,
George
|
|
|
|
|
Hello all,
I am getting error message:
Unhandled exception:Stack overflow.It is due to the declaration of too large array sizes.
But how can i overcame that problem
The code presented here is given below:
FILE *fp1,*fp2,*fp_write,*fpw,*fp_col;
int width,height;
int buffer,buffer1,buffer3;
int k=0,p=0;
unsigned int blueValue=0,redValue=0,greenValue=0;
unsigned int grayValue=0;
unsigned char *pChar;
unsigned char someChar;
long int iHist[256];
float hist[256];
long int total_pixels=0;
int col[257499];
int C[561][459];
int m=0;
fp1=fopen("D:\\Pictures\\mod.bmp","rb");
if(fp1==NULL)
{
printf("file doesn't open");
return;
}
fseek(fp1,1078,SEEK_SET);
k=0;
while(!feof(fp1))
{
fread(&buffer,1,1,fp1);
col[k]=buffer;
k++;
}
int i=0;
int j=0;
k=0,m=0;
for(m=0;m<258878;m++)
{
C[i][j]=col[k];
j++;
k=k+561;
if((j%459==0) &(j!=0))
{
i=i+1;
k=i;
j=0;
}
if(i>561)
break;
m++;
}
Regards
|
|
|
|
|
your loop seems to exceed the array boundarys.
any way,
debug it and see.
how ever arrays of that size are not suggested.
please tell me your idea behind the algo, such that, i can suggest you something.
|
|
|
|
|
Probally too big static variables.
take a look at this thread (yesterday)
stack vs heap[^]
Russell
|
|
|
|
|
Maynka wrote: int col[257499];
int C[561][459];
In addition to Russell's reply...
These too arrays are WAY to big for a typical stack: 2,059,992 bytes!!
You'll probably want to allocate thes on the heap
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
Thanks for your reply.How can i allocate variables on heap in VC++.
Regards,
Mayank
|
|
|
|
|
You can use the new operator...
See this[^] thread for more info.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
I'm currently trying to implement a pan function for panning images which are displayed in a picture control area (drawing with GDI+).
I've managed to change the mouse cursor, it should be a hand when the cursor is over the picture control and an arrow everywhere else. A part of that seems to work. I check if the mouse position is inside the area of the picture control but somehow the area "thinks" it's startpoint (upper left) is located @ x: 0 y: 0; in fact it is placed somewhere in the middle of the dialog box.
Here is the snippet:
void CTrackAndTraceDlg::OnMouseMove(UINT nFlags, CPoint point)
{
HCURSOR hcur = NULL;
CRect rc;
m_pictureControl.GetClientRect(&rc);
rc.NormalizeRect();
POINT MousePosition = point;
BOOL isOnPictureControl = PtInRect(&rc, MousePosition);
if(isOnPictureControl && m_bPicLoaded && hcur == NULL)
{
hcur = LoadCursor(AfxGetApp()->m_hInstance,(LPCTSTR)IDC_CUR_PAN);
SetCursor(hcur);
}
else
{
SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
hcur = NULL;
}
CDialog::OnMouseMove(nFlags, point);
}
As you see I get the rectangle from the m_pictureControl (which is a var for the Picture Control on the dialog). But why it gives back the wrong x,y -> the rc.Width and rc.Height are correct.
Any ideas?
Thx, Shi
|
|
|
|
|
can u just put your query into different words such that, they are more cleaar to understand?
|
|
|
|
|
in short:
- I'm using a Picture Control on my Dialog
- It's placed in the middle of the Dialog
- I'm getting the position and dimension of the Picture Control with "CRect rc;" AND "m_pictureControl.GetClientRect(&rc);"
- When I Debug I see that the position of the "rc" is TOP: 0 LEFT: 0 -> Why that, I can clearly see it's not on that Postion of the Dialog.
-> So while this gives me back the "wrong" information about the location, I cannot properly use my pan function (draging image to move it).
Hope that made it a bit clearer
Shi
|
|
|
|
|
that 0,0 you are seeing is that of the control with respect to itself not with respect to the dialog.
but my doubt is how you cn write your logic to pan that image using the picture control.
how ever,
i have my own Active X control, which can take a large bitmap and has the feature of panning.
|
|
|
|
|