|
Hi,
I am doing Http Get and Post operation using WebClient class of System.Net.
Is there a way to block cookies while i am doing this operations?
|
|
|
|
|
Hi,
I have working code of above function in vc++. I need help to convert it to c#....Any one know how to achieve this in c# please help me out here.
The code i got is from this link....
http://www.codeproject.com/dll/Execute_DLL_Function.asp
bool GetDLLFileExports(char *szFileName, unsigned int *nNoOfExports, char **&pszFunctions)
{
HANDLE hFile;
HANDLE hFileMapping;
LPVOID lpFileBase;
PIMAGE_DOS_HEADER pImg_DOS_Header;
PIMAGE_NT_HEADERS pImg_NT_Header;
PIMAGE_EXPORT_DIRECTORY pImg_Export_Dir;
hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if(hFile == INVALID_HANDLE_VALUE)
return false;
hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
if(hFileMapping == 0)
{
CloseHandle(hFile);
return false;
}
lpFileBase = MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0);
if(lpFileBase == 0)
{
CloseHandle(hFileMapping);
CloseHandle(hFile);
return false;
}
pImg_DOS_Header = (PIMAGE_DOS_HEADER)lpFileBase;
pImg_NT_Header = (PIMAGE_NT_HEADERS)((LONG)pImg_DOS_Header + (LONG)pImg_DOS_Header->e_lfanew);
if(IsBadReadPtr(pImg_NT_Header, sizeof(IMAGE_NT_HEADERS))||pImg_NT_Header->Signature != IMAGE_NT_SIGNATURE)
{
UnmapViewOfFile(lpFileBase);
CloseHandle(hFileMapping);
CloseHandle(hFile);
return false;
}
pImg_Export_Dir = (PIMAGE_EXPORT_DIRECTORY)pImg_NT_Header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
if(!pImg_Export_Dir)
{
UnmapViewOfFile(lpFileBase);
CloseHandle(hFileMapping);
CloseHandle(hFile);
return false;
}
pImg_Export_Dir= (PIMAGE_EXPORT_DIRECTORY)ImageRvaToVa(pImg_NT_Header,pImg_DOS_Header, (DWORD)pImg_Export_Dir, 0);
DWORD **ppdwNames = (DWORD **)pImg_Export_Dir->AddressOfNames;
ppdwNames = (PDWORD*)ImageRvaToVa(pImg_NT_Header, pImg_DOS_Header, (DWORD)ppdwNames, 0);
if(!ppdwNames)
{
UnmapViewOfFile(lpFileBase);
CloseHandle(hFileMapping);
CloseHandle(hFile);
return false;
}
*nNoOfExports = pImg_Export_Dir->NumberOfNames;
pszFunctions = new char*[*nNoOfExports];
for(unsigned i=0; i < *nNoOfExports; i++)
{
char *szFunc=(PSTR)ImageRvaToVa(pImg_NT_Header, pImg_DOS_Header, (DWORD)*ppdwNames, 0);
pszFunctionsIdea = new char[strlen(szFunc)+1];
strcpy(pszFunctionsIdea,szFunc);
ppdwNames++;
}
UnmapViewOfFile(lpFileBase);
CloseHandle(hFileMapping);
CloseHandle(hFile);
return true;
};
|
|
|
|
|
I'm rewriting a project from C++(MFC) to C#, mostly to learn this new language. In that project I use CAsyncSocket to create a TCP connection with another peer in a network to send some notification messages or some very small amount of data or a requests.
I tried to find a similar easy way to implement an asynchronous TCP connection in C#, but most of them are not.
Is there any alternative to that in C#? Is there any component or namespace or class that can help me do it quickly?
// "Life is very short and is very fragile also." Yanni while (I'm_alive) { cout<<"I love programming."; }
|
|
|
|
|
System.Net.Socket namespace?
only two letters away from being an asset
|
|
|
|
|
Thanks Mark.
Mark Nischalke wrote: only two letters away from being an asset
// "Life is very short and is very fragile also." Yanni while (I'm_alive) { cout<<"I love programming."; }
|
|
|
|
|
System.Net.Sockets namespace is what you want if you still want to use sockets.
.NET has a nice abstraction over sockets called Remoting. With remoting, instead of sending bytes over the pipe, you connect to a .NET object on the other end and call functions on it like a regular object. If you're interesting in .NET remoting, check out the System.Runtime.Remoting namespace, as well as the System.Runtime.Remoting.dll in the .NET framework.
Finally, the new "cool" way of cross-process communication is WCF (Windows Communication Foundation). It's new in .NET 3 and provides a messaging-based, loosely-coupled, service architecture. There are articles here at CP as well as articles around the net on how to use WCF.
|
|
|
|
|
Judah Himango wrote: System.Net.Sockets namespace is what you want if you still want to use sockets.
Ireally prefer not to do it that way. It needs a lot of works, I think.
Remoting and WCF.
Thanks alot judah.
I'm going to check them right now.
// "Life is very short and is very fragile also." Yanni while (I'm_alive) { cout<<"I love programming."; }
|
|
|
|
|
Is there a way to use Socks4, Socks4a or Socks5 proxy types with WebProxy class.
I have downloaded a Proxy Server "ccproxy" from
http://www.youngzsoft.net/ccproxy/screenshot.htm
where i can use my code to download and upload files but it works only with Port 808 reserved for HTTP proxy in ccproxy server.
Http Get Code...
WebClient client = new WebClient();
if (tbpassword.Text != "" && tbUsername.Text != "")
{
NetworkCredential auth = new NetworkCredential(tbUsername.Text, tbpassword.Text);
client.Credentials = auth;
}
if (tbProxyAddress.Text != "" && tbProxyPort.Text != "")
{
WebProxy proxy = new WebProxy(tbProxyAddress.Text, Convert.ToInt32(tbProxyPort.Text));
if(tbProxyUsr.Text != "" && tbProxyPwd.Text != "")
proxy.Credentials = new NetworkCredential(tbProxyUsr.Text, tbProxyPwd.Text);
client.Proxy = proxy;
}
Uri uri = new Uri(tbURL.Text);
client.DownloadFile(uri, tblocalFile.Text);
client.Dispose();
HTTP Post Code...
WebClient client = new WebClient();
if (tbpassword.Text != "" && tbUsername.Text != "")
{
NetworkCredential auth = new NetworkCredential(tbUsername.Text, tbpassword.Text);
client.Credentials = auth;
}
if (tbProxyAddress.Text != "" && tbProxyPort.Text != "")
{
WebProxy proxy = new WebProxy(tbProxyAddress.Text, Convert.ToInt32(tbProxyPort.Text));
if (tbProxyUsr.Text != "" && tbProxyPwd.Text != "")
proxy.Credentials = new NetworkCredential(tbProxyUsr.Text, tbProxyPwd.Text);
client.Proxy = proxy;
}
Uri uri = new Uri(tbURL.Text);
System.Collections.Specialized.NameValueCollection collect = new System.Collections.Specialized.NameValueCollection();
collect.Add("input", "Ronak");
collect.Add("submit", "Submit");
byte[] btArray = client.UploadValues(uri, "POST", collect);
//byte[] btArray = client.UploadFile(uri, "POST", tblocalFile.Text);
MessageBox.Show(Encoding.UTF8.GetString(btArray));
client.Dispose();
|
|
|
|
|
Hi all,
I'm working on a project using Visual Studio2005. I have saved an image path to the database. The code is something like this:
-----------------------------------------------
.
.
.
OpenFileDialog openImgFile = new OpenFileDialog();
if (openImgFile.ShowDialog() == DialogResult.OK)
{
imgPath= openImgFile.FileName;
pictureBox1.Image = Image.FromFile(imgPath);
}
cmdStr = "insert into img_tbl(imgID,imgPath)values('01',@path)";
cmd = new SqlCommand(cmdStr, cnn);
SqlParameter path = new SqlParameter("@path", SqlDbType.NVarChar, 225);
path.Value = imgPath;
cmd.Parameters.Add(path);
cmd.ExecuteNonQuery();
.
.
.
What I got from that is an image path storing in the database, something like this:
C:\Documents and Settings\Desktop\foto_311.jpg
But the problem is when I use this path to get an image to display on a form, it dosen't work!
If I change a little like this:
C:\\Documents and Settings\\Desktop\\foto_311.jpg
then it works.
So can anyone tell me how to change it before being saved?
Thankz
|
|
|
|
|
|
The retrieve code not included there
|
|
|
|
|
only two letters away from being an asset
|
|
|
|
|
I have created a addin for outlook 2003 using c# and installing using setup project. How can i prompt user to close outlook if it is open during install/uninstall?
In setup project how can i add this condition?
|
|
|
|
|
You can get all processes by some name:
<br />
Process [] localByName = Process.GetProcessesByName("notepad");<br />
But it is not a strong solution. User can modify name of a file executes an outlook so you didn't get it
|
|
|
|
|
I've noticed a odd problem when using a class that implements IList<T> with a BindingSource. I've managed to reproduce the problem with some simple classes. I have a class called BaseClass and several classes that derive from BaseClass called DerivedClass1, DerivedClass2 and DerivedClass3.
Now I create a class to act as a collection of BaseClass objects called BaseClassCollection. BaseClassCollection implements IList<T> and basically just wraps a List<BaseClass> at this point. At this point everything works fine and I can populate the BaseClassCollection with objects of type DerivedClass1, DerivedClass2 and DerivedClass3 to create a heterogenous collection.
Now the problem comes when I try and use BaseClassCollection as a DataSource for a BindingSource. I create a form with a ListBox control with it's DataSource set to a BindingSource. I then set my BindingSource to bind to an empty BaseClassCollection. Then I add three buttons that will add either a DerivedClass1, DerivedClass2 or a DerivedClass3 object to the collection and refreshes the BindingSource. If I add several objects of the same type then I have no problem, but as soon as I try to add a object of a different class I get an exception:
The value "BindingTest.Derived2" is not of type "BindingTest.Derived1" and cannot be used in this generic collection.
Parameter name: value
It seems that when you set the DataSource of the BindingSource to an IList<T> it looks at the first item in the list (let's say it's a DerivedClass1) and assumes that the list is a DerivedClass1 list and won't let you add anything that isn't a DerivedClass1. What it should do is recognize that it's an IList<baseclass> and assume we have a list of BaseClass and thus allow the addition of any class derived from BaseClass. Oddly enough, if I make my BaseClassCollection inherit from List<BaseClass> instead or implementing IList<BaseClass> then it works as expected, but I lose the ability to control the implemenation of the list.
Does anybody know what is happening here? How do I make the BindingSource realize that it's dealing with a collection of BaseClass?
-- modified at 21:21 Friday 8th June, 2007
Fixed by < and > which completely changed the meaning of the question
|
|
|
|
|
By comparing the IList<T> interface with the List<T> class I noticed that one difference is that List<T> implements IList as well as IList<T>. Implementing IList in addition to IList<T> in my class seemed to fix the problem, although I have no idea why?
|
|
|
|
|
I am currently developing a Form that will scan a plugins directory and load any dll files that have a baseType of "MadPages.PageBase"
For proof of concept, I created a Control that extended the PageBase class. The form application found the dll file and loaded it into the application as planned.
My new problem is this. I have a new project in the solution named ProjectA. ProjectA is another control library that extends the PageBase class. ProjectA has a reference to another project which I called ProjectB. When my form application finds the DLL file for ProjectA, I do a foreach loop on the dll file's GetTypes().
This of course now comes up with 2 types...PageBase and ProjectB. When I try to dynamically load the Type PageBase into a local PageBase variable, I get an exception stating that it cannot find the dll for ProjectB. If I add a reference to my main form's project (pointing to to ProjectB), the application can load ProjectA. I know I must be doing something wrong.
The point of having these plugins was so I don't have to touch the main form's project when I want to extend it. Please let me know what I am doing wrong. Here is the code on how i'm loading my dll files from the plugin-dir:
Assembly asm= Assembly.LoadFile(path);
foreach (Type t in asm.GetTypes())
{
if (t.BaseType.ToString() == "MadPages.PageBase")
{
return (PageBase)t.GetConstructors()[0].Invoke(new object[] { });
}
}
There is only one constructor for the PageBase class. Thanks!
|
|
|
|
|
One more little thing I found out while de-bugging. If I step through the constructor for ProjectA, as soon as it tries to make a call to ProjectB it bombs meaning that it cannot find the file.
When I compile ProjectA and run it, everything is fine. The ProjectB's dll file is in the same folder as ProjectA's. I am copying these dll files over to a plugins directory for the main application. Both dll files are once again in the same folder but it looks like once I copy both of them to another directory, ProjectA doesn't find the dll for ProjectB. Someone wanna school me on this awful Friday?
|
|
|
|
|
|
Worked! I owe you a beer good sir. Thanks a lot!
|
|
|
|
|
Make it a Guiness
only two letters away from being an asset
|
|
|
|
|
Hi all,
going nuts... i placed a windows media player on my form (tried the 6.4 version and version 10) and like to play a mkv file (720p x264).
I can play the mkv in the old media player that comes with xp (C:\Program Files\Windows Media Player\mplayer2.exe) without any problems.
The embedded player tries to connect to the internet, probably to find a codec.
It only plays the sound.
Does anyone know how i can make the mkv play in my form ?
thanx a lot.
|
|
|
|
|
Matroska (Mkv) is just a container (like avi), so the file format says nothing about the codec used. Try installing CCCP, and it will probably work.
Standards are great! Everybody should have one!
|
|
|
|
|
i don't want to install other codecs, since it works in the standard windows mediaplayer, it should work in my embedded player too.
|
|
|
|
|
Hai Everybody,
I want to encrypt the user name and password given by the user separately and i have to store the encrypted content in sql server. yesterday our forum members suggested me to use the SHA256 algorithm so that i referred one article in our forum but it encrypts and decrypts some file contents.
I felt very difficult to understand also.
So can anyone suggest me some other simple and strong algorithm.
Best Regards,
M. J. Jaya Chitra
|
|
|
|