Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all 8156 articles
Browse latest View live

Overlay image not working 64bits application

$
0
0

I have a windows application in c#. The application is 32bits. We have used following method to set the overlay image in the treeview. The function works perfectly. Now, we have change the platform target from x86 to x64. But since then, the overlay overlay image is not set in the treeview node. It seems that the code does not work on 64bits.

Could anybody suggest why this code works on 32bits application and not for 64bits application?

The code neither throws any exception nor work correctly.

Ref: http://msdn.microsoft.com/en-us/library/windows/desktop/bb760017(v=vs.85).aspx http://msdn.microsoft.com/en-us/library/windows/desktop/bb773456(v=vs.85).aspx

[DllImport("user32.dll", CharSet = CharSet.Auto)]
    public static extern IntPtr SendMessage(IntPtr hWnd, IntPtr msg, IntPtr wParam, ref TVITEM lParam);

private const int TVIS_OVERLAYMASK = 0x0F00;
private const int TVIF_HANDLE = 0x08;
private const int TVIF_STATE = 0x0F;



[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Auto)]
public struct TVITEM
{
    public uint mask;
    public IntPtr hItem;
    public uint state;
    public uint stateMask;
    public IntPtr pszText;
    public int cchTextMax;
    public int iImage;
    public int iSelectedImage;
    public int cChildren;
    public IntPtr lParam;
}

public bool SetNodeOverlayImage(TreeNode node, int overlayIndex)
    {          
        try
        {
            if (overlayIndex < 0 || overlayIndex > 4)
                return false;

            var tvi = new TVITEM
                          {
                              mask = TVIF_HANDLE | TVIF_STATE, 
                              hItem = node.Handle
                          };


            SendMessage(Handle, (IntPtr)WindowsMessages.TVM_GETITEM, IntPtr.Zero, ref tvi);

            uint prevState = tvi.state & TVIS_OVERLAYMASK;

            if (prevState == overlayIndex << 8)
                return false;

            tvi.mask = TVIF_HANDLE | TVIF_STATE;
            tvi.hItem = node.Handle;
            tvi.state = (uint)overlayIndex << 8;
            tvi.stateMask = TVIS_OVERLAYMASK;

          SendMessage(Handle, (IntPtr)WindowsMessages.TVM_SETITEM, IntPtr.Zero, ref tvi);

            return true;
        }
        catch
        {}
        return false;
    }





Reproducible bug in ZipFile CreateFromDirectory

$
0
0

I've already posted my question in social msdn here: http://social.msdn.microsoft.com/Forums/vstudio/en-US/362ba799-33ca-45c3-9581-36a85d531d66/reproducible-bug-in-zipfile-createfromdirectory but was asked to repost to this forum. 

When creating single zip file from large directory of logs (over ~45GBs) by calling System.IO.Compression.ZipFile.CreateFromDirectory, the function finishes without any errors, however the resulting zip archive cannot be completely unpacked - neither by built in windows zip files support, nor by calling complement function System.IO.Compression.ZipFile.ExtractToDirectory. The ExtractToDirectory is able to unpack approximately first 45GBs and then throws InvalidDataException:

System.IO.InvalidDataException: A local file header is corrupt.
   at System.IO.Compression.ZipArchiveEntry.ThrowIfNotOpenable(Boolean needToUncompress, Boolean needToLoadIntoMemory)
   at System.IO.Compression.ZipArchiveEntry.OpenInReadMode(Boolean checkOpenable)
   at System.IO.Compression.ZipArchiveEntry.Open()
   at System.IO.Compression.ZipFileExtensions.ExtractToFile(ZipArchiveEntry source, String destinationFileName, Boolean overwrite)
   at System.IO.Compression.ZipFileExtensions.ExtractToDirectory(ZipArchive source, String destinationDirectoryName)
   at System.IO.Compression.ZipFile.ExtractToDirectory(String sourceArchiveFileName, String destinationDirectoryName, Encoding entryNameEncoding)
   at System.IO.Compression.ZipFile.ExtractToDirectory(String sourceArchiveFileName, String destinationDirectoryName)

I've already reported this in this question: http://social.msdn.microsoft.com/Forums/vstudio/en-US/5a3c7824-192a-4bc2-8ef0-be0b08b2f6a5/zipfile-createfromdirectory-creating-corrupted-archive and I apologize for reposting, however this is causing us serious issues, as we are using ZipFile.CreateFromDirectory function in our financial application where we are legally obligated to retain some history of logs and now it turns out that we cannot access portion of our logs (as we always delete the original logs once the ZipFile.CreateFromDirectory successfully creates the archive because there is several dozens of GB logs data per day).

I've been able to repeatedly reproduce this with ~60GB folder (with text files each about 100 - 300MB large) when just simply calling ZipFile.CreateFromDirectory to archive this folder and then calling ZipFile.ExtractToDirectory to unpack it.

Thanks
Jan

TCP Socket with HTTP POST

$
0
0

My client requires the following mode of communication

  1. Your software opens a socket from your client platform to connect our server platform.
  2. Our server will respond by starting the “keep alive” dialog.
  3. Your software will send an X12 transmission packet with a request
  4. Our server will check the request and respond with a response.

This is how  a typical transmission looks like

Request

POST /OKMMISPOS HTTP/5.1
Content-Length: 521

<Body of the request>

Response

HTTP/5.1 200 OK
Content-Length: 448

<Body of the response>

This is all the information that was provided to me. There is no URL, Host Header for the Request. This connection is established using a tunnel. So we have a source IP:Port connecting to their destination IP:Port. I am using to connect to our source and then send a request to their IP:Port. This is all the information they want in the request. No URl's, no host, port. Only  what is listed above.

So here's how I went about doing this.

   private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                //create a new client socket ...
        // This will be the destination servers IP/Port
           string szIPSelected = "1:2:43:1";
           int szPort = 00000;
           Socket m_socClient = new Socket    (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
           System.Net.IPEndPoint remoteEndPoint = new System.Net.IPEndPoint(szIPSelected , szPort);
          m_socClient.Connect(remoteEndPoint);
           if (m_socClient.Connected)
            {
        string resource= "/OKMMISPOS";                       
var header = String.Format("POST {0} HTTP/5.1 " + Environment.NewLine, resource);
        String body = "Body of my request";
        byte[] bodyBytes = Encoding.ASCII.GetBytes(body);
            header += "Content-Length: " +  (bodyBytes.Length) + Environment.NewLine + Environment.NewLine;
        string request = String.Concat(header, body);
        byte[] bytesToSend = Encoding.ASCII.GetBytes(request);
       byteCount = m_socClient.Send(bytesToSend, SocketFlags.None);

         toolStripStatusLabel1.Text = "Sending  Request to  " + szIPSelected + ":" + szPort;
                    statusStrip1.Refresh();
                    byte[] bytesReceived = new byte[1024];
                    byteCount = m_socClient.Receive(bytesReceived, SocketFlags.None);
                    txtResponse271.Text =
                           Encoding.ASCII.GetString(bytesReceived);
                    m_socClient.Disconnect(false);
                    m_socClient.Close();
                }
            }
            catch (Exception se)
            {
                MessageBox.Show(se.Message);
                m_socClient.Close();
                MessageBox.Show(se.Message);
            }
            finally
            {
                 m_socClient.Disconnect(false);
                m_socClient.Close();
            }


            

            }

I am using a Socket and connecting it to a endpoint. Sending the entire reques by appending the required 2 lines in the Header including the content length. The socke sends a message, receives it.

THis seems to be good. Although I a getting a HTTP bad request.

POST /OKMMISPOS HTTP/5.1
Content-Length: 484

RequestBody

Response;

HTTP/1.1 400 Bad Request
Content-Length: 484

ResponseBody

This is how my request and response  looks like.

Wireshark didn't give me a lot of info except protocols and HTTP Bad request. Please suggest.

Thank you

sun


sunDisplay

Access WMI to nated machine

$
0
0
Hi,
    I try test access WMI to a nated machine with the utility wbemtest and give me this error: error number "0x80070776", The object exporter specified was not found.
    I make the same test, with out the nat, and work fine. Anyone knows why this I cant access the WMI via a nated IP ?

Thanks

How to print a word document on the server from the client

$
0
0

hi everyone
i  need to print a word document on the server from client using ASP.net, i tried the next code:


ProcessStartInfo info = new ProcessStartInfo(fileCopy);
info.WindowStyle = ProcessWindowStyle.Hidden;
info.Verb = "PrintTo";
info.Arguments = "PrinterName";
Process process = Process.Start(info);
fnDeleteDocument(fileCopy);

But in my computer works well and when i put my application to the server it is not working :(

anyone know why?

Thanks in advance




Do we have the CCC(clear command channel) and SSH/SFTP support in .net FtpWebRequest class?

$
0
0

Hello,

I am using C3 .net 4.0, do we have the CCC(clear command channel) and SSH/SFTP support in .net FtpWebRequest class?

Thanks, Nitin

How to convert varchar to decimal and decimal to varchar? c#

$
0
0
How to convert the text of a textbox to decimal (because I want to put in in a database decimal field)?

How to stop/start a Windows Task

$
0
0

I don't know if this is the right place to ask this, but I am trying to Stop/Start a Scheduled Windows Task which sometimes Hangs. I have a Powershell script which currently uses .Net to interrogate the Task object and I can display the Task's attributes, but I don't know how to Stop and then Start/run the task.  There are probably methods to do so, but I am kind of new to this and am challenged when it comes to locating methods.

Best regards,

Michael


Epson Receipt Printer prints very slow (POS for .NET)

$
0
0

Information you need:

  • .Net Framework 4.0
  • VS 2010 , C#
  • Microsoft.PointOfService.dll  Ver POS for .Net 1.12
  • Epson TM-T20 Thermal Printer (USB port)

Everything is good and works fine, there is no problem with the codes and installations.

The Problem is when I want Print a simple Receipt with no Logo or image or bar code, It takes many times almost 20 Second for 25 simple lines. and print every lines with a little delay. and the printer is noisy like dot printer.

But, when I press TestPrint button in the Print Drive is very faster than my codes and no noise.

I am using the OPOS code for .Net which was provided in CD Driver of Epson.

this is  a sample of print code:

 m_Printer.PrintNormal(PrinterStation.Receipt, "\u001b|cA" + "*** Customer Copy***" + "\n");

Please, help me, I will get into trouble if I could not solve this problem.

Thanks,

Mehdi



Is this my fault?

$
0
0

While creating a new class, I added a line,"using System.Data.sqlClient;" to the top of CS file. I declared an instance variable of sqlCommand, m_Comm, and I defined the variable," m_Comm = new sqlCommand();"

But, visual studio professional 2013 preview showed a message saying,"Expected class, delegate,or Enumrration" with red line under the name of class, sqlCommand I checked if there was a typo, but,nothing. I can't understand what happened. Would you let me know how I can solve this problem?

Performance decreased after Unicode Support to application

$
0
0

Hi All Expert,

      I provided Unicode support to my application and for that I used std::wstring, wchar_t and unicode/wide version of windows function.

I also had to convert the string from UTF8 to UTF16 and UTF16 to UTF8 on many places in code.

I also localized all error/warning messages and string literals for porting application in multiple languages. Now I am facing the Performance issue with our application. The performance has been decreased more than 25 percent and it is very huge.

May you expert suppose or suggest that which are the cause of performance decrease of application 

Please help me for this if any one know any thing about it.

 

P/Invoke - passing C# string to function in C DLL

$
0
0

My DLL exports the following function:
void  __stdcall __declspec(dllexport) SetValue(char *value);

I found an example that suggested that to call this function from C#, one should:
- convert the string to a byte array, e.g. 
byte[] byteArray = newASCIIEncoding().GetBytes(stringVariable);

and then pass the byte array:
MyClass.SetValue(byteArray);

This works consistently, but why? SetValue expects a NULL-terminated string. I do not explicitly append a 0 byte, so is P/Invoke doing it for me, or am I just lucky for now, until one day when failure will cause the most damage? The example did not add a 0 byte.

By the way, declaring SetValue as
DllImport("my.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
publicstaticexternvoidSetValue([MarshalAs(UnmanagedType.LPStr)]stringfilename);
which I originally tried, does not work.

I am using VS Express 2012 and the .NET Framework 4.0.

Crystal Reports PDF not finishing

$
0
0

I'm having a problem generating Crystal Reports on my Windows 2008 R2 server. The server is 64-bit but we are using the 32-bit Crystal Reports RTE for VS 2010. The problem I'm seeing is that when the Crystal Reports engine creates the files in the TEMP folder (C:\Windows\Temp) one file appears to be created with the wrong permissions.

There are three temp files:

  • RptConMgrCache  - All users have full control
  • RPT  - All users have full control
  • TMP - One user - our service account - has only read and write.  I suspect it needs either modify or full control

Is there a missing configuration step?

AM DOING TRAINING IN VB.NET

$
0
0
How to get the event of maximum box when it clicked and minimum box when it clicked of the form

Security Considerations for Reflection under .NET 4.0

$
0
0

The following codes works fine under .NET 2.0.

But under .NET 4.0. The value of AutoIncrementCurrentFieldInfo is NULL, so it will throw exception when execute " AutoIncrementCurrentFieldInfo.GetValue(dataColumn);".

I got the explanation in following link:

http://stackoverflow.com/questions/4441561/fieldinfo-getvalue-return-null-for-a-private-member-while-debugger-indicates-fie

"This is caused by the security model in .net 4.0, as you're running an asp.net application, which is probably not running in full trust. As the field is security critical, you can't access it through reflection.

You can read a bit on the msdn about: Security Considerations for Reflection"

My question is that how to modify below codes in order that it still works fine under .NET 4.0.

using System.Reflection;


private static readonly FieldInfo AutoIncrementCurrentFieldInfo =
            typeof(DataColumn).GetField("autoIncrementCurrent", BindingFlags.Instance | BindingFlags.NonPublic);


private static BitVector32 GetDataColumnFlags(DataColumn dataColumn)
{

long current = (long) AutoIncrementCurrentFieldInfo.GetValue(dataColumn);

}

Thanks

Scott



Debug.Diagnostics intialization failed after installing Security Patch KB2840628

$
0
0

I get the below error in my application while trying to invoke my webservice through the proxy class. This happens in windows 7 64 bit machine.

This is happening after applying windows security patch KB2840628

The proxy class is been inherited from Microsoft.Web.Services3.WebServicesClientProtocol

An error occurred creating the configuration section handler for system.diagnostics: Attempt by method 'System.Configuration.TypeUtil.CreateInstanceRestricted(System.Type, System.Type)' to access method 'System.Diagnostics.TraceSection..ctor()' failed.

When i remove the System.Diagnostics section in my app.config file it works out fine.

My current section looks like below

<system.diagnostics><sources><!-- This section defines the logging configuration for My.Application.Log --><source name="DefaultSource" switchName="DefaultSwitch"><listeners><add name="FileLog"/><!-- Uncomment the below section to write to the Application Event Log --><!--<add name="EventLog"/>--></listeners></source></sources><switches><add name="DefaultSwitch" value="Information"/></switches><sharedListeners><add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter"/><!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log --><!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> --></sharedListeners></system.diagnostics>
Do i realy need to remove this section?


Raamakarthikeyan

.Net Framework Class

Socket.Receive() multiple calls necessary

$
0
0

Hi,


When larger byte[]s are Sent/Received, we need to call Received multiple time, to get the sent amount of data.

Reading the MS docu (http://msdn.microsoft.com/de-de/library/26f591ax.aspx) it states:

'If you are using a connection-oriented Socket, the Receive method will read as much data as is available, up to the number of bytes specified by the size parameter.'

For me this means, that we get all the sent data in *one* call, not in several.

Did we miss something? Or is there a link to how to officially use it. Example, etc?

Thanks,

Christian

Combine XLS file and HTML files into XLSX file

$
0
0

Hi all, this is my first time posting and I am having a problem in researching how to combine XLS and HTML into a XLSX.

I would like to avoid using Excel directly to create excel file (using OLEDB Automation or Excel Interop objects). Ideally I would like to use any open source class libraries with some documentation and samples.


Here is the scenario I would like to achieve:

User has one large XLS file and multiple HTML files with tables (I cannot change this).

Depending on some user selections I need to generate new XLSX file (I can change this into XLS) from a part of the specific XLS sheet and from an HTML file which has a same name as that sheet.


Any guidelines would be appreciated, if possible please provide some links or snippet codes for any of required task.

Thank you in advance.



can i BeginAcceptTcpClient for more than once in TcpListener?

$
0
0

hi all, i am trying to write a tcp service with TcpListener. when i am trying to call TcpListener.BeginAcceptTcpClient for more than once, sometime, it will stuck, and no incoming connections can be generated.

briefly my code looks like following,

for i as int32 = 0 to 1

listener.BeginAcceptTcpClient(addressof callback, nothing)

end

while my callback is simple like,

dim c as TcpClient = listener.EndAcceptTcpClient(iar)

it looks like when two callbacks fired together, it may fail, any hints?

thank you.

Viewing all 8156 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>