krosty4782 0 Light Poster

Hello, im new to asm, and im trying to code some kind of notepad.
At the moment, my program create a file, and open a file.
Now i want to be able to edit the opened file. I ve thought in one option:
When i open the file, it shows it in the console, so one option is to give the user the option of modify the console text, and then, when i need to save the file, take all the text in screen and rewrite it over the original txt. I know how to give the user the option to modify text in console, but i don't know how to seek the pointer to begining of console, using interruption 21h 42h, i need a handle, it is possible to get the handle of the console and use seek to place pointer to 0 and then get all writed text?
What other option can i use ?
note: i don't want only to append text, i want to be able to modify and add text in any position.

Thanks

krosty4782 0 Light Poster

The problem of using writeallbytes is that it will write the "mystring", thats why i ve first converted all to string.

krosty4782 0 Light Poster

Hi.
I want to make a program to download files from a remote host.
So what i do is to send throw sockets all the binary information + a string used as end "mystyring".
To check if i have to continue writing the buffer to the file i first convert all to string, so if i find "mystring" it will finish, if not, i reconvert all to bytes and i copy data.
The problem im having is that, .txt files are writed well, but binaris not, it always show error at opening. I ve tried copying a pdf, and when i open it show all the pages, but in blank :S. Also if i check the size of the original file is always some bytes bigger than the copy.

FileStream fs = new FileStream("C:\\Users\\Mauri\\Desktop\\" + item.Name, FileMode.Append, FileAccess.Write);
            BinaryWriter writer = new BinaryWriter(fs);
            bool continua = true;
            while (continua)
            {
                recibido = getSocket(numsock).socketRecv(); // This return the data converted to string.
                words = recibido.Split('|'); //We split "|mystring" to find the end of file.
                foreach (string s in words)
                {
                    if ((String.Compare(s, "mystring") != 0))                        
                        writer.Write(StringToBytes(s)); // Write converted data. 
                    else
                        continua = false; // if we find "mystring", end the action.
                }   
            }
            writer.Close();
            fs.Close();

// Convert string to bytes
public byte[] StringToBytes(String cadena)
        {
            System.Text.ASCIIEncoding codificador = new System.Text.ASCIIEncoding();
            return codificador.GetBytes(cadena);
        }

The strange thing is that .txt files are writed correctly.
Thanks

krosty4782 0 Light Poster

I have been trying but without success.
I have this code:

while (!String.Equals(opasgard, "opasgarfinish"))
            {
                coming = getSocket(numsock).receiveDownload();
                opasgard = encoding.GetString(coming);
                if(!String.Equals(opasgard, "opasgarfinish"))
                bw.Write(coming);
            }
            bw.Close();
            fs.Close();

And the receive function:

public byte[] receiveDownload()
        {          
                buffer = new byte[13];
                string[] words;
                len = socket.Receive(buffer);
                i = (buffer.Length) - 1;
                while (buffer[i] == 0)
                    --i;
                // now bar[i] is the last non-zero byte
                bar = new byte[i + 1];                           
                words = System.Text.Encoding.UTF8.GetString(bar).Split('|');                
                if (words.Contains("opasgarfinish"))
                {
                    System.Text.ASCIIEncoding  encoding=new System.Text.ASCIIEncoding();
                    Byte[] opasgard = encoding.GetBytes("opasgarfinish");
                    return opasgard;
                }
                return bar;   
        }

And the file is made, but now with the correct chars, i get:

**You have 敲挀攀椀瘀攀搀 琀栀攀 猀oftware as p牡琀 漀昀 琀栀攀 嘀椀猀ual Studio 9〮 䈀攀琀愀 倀爀漀最爀愀m.

When it must be:

**You have received the software as part of the Visual Studio 9.0 Beta Program.

Any idea?

krosty4782 0 Light Poster

So you say to do a while loop, to receive all the data in more than one step ?
I have tried that, but i have two problems the one is that i don't know how to properly safe the temp buffer and then join with the other buffer that are received.
Suppouse, i send a data that is read in 5 times by mu buffer.
How could i save the 5 parts (in bytes) and join them propertly ?
And the other thing is, that i don't know when to stop the while loop.
If i send 3mb data, how do i know when all data is received and stop the loop?

Thanks

krosty4782 0 Light Poster

Hi!

There is anyway to make the buffer size of a socket dynamic ?
Because i need to download some things and my buffer of 1024 bytes cant get all the information.
How could i do this ?
Thanks

krosty4782 0 Light Poster

Thanks

krosty4782 0 Light Poster

How do i mark as solved?

krosty4782 0 Light Poster

Yeah, thanks, i didn't reallize that there was such method.

krosty4782 0 Light Poster

Hi ppl

I need to edit a listviewItem to change name so i use "beginedit()", but then i need to send the new name. The problem is, there is not way to see when edit is finished to send the new name.
So, any idea of how could i do to send the new edited name ?

Thanks

krosty4782 0 Light Poster

Hey!!

I have two codes, one in c++ and the other in c# i think the problem is in the c# code, in the receive() method.

I have this:

while (!aa.Equals("filemanagerstop"))
            {                
                aa = getSocket(numsock).socketRecv();
                MessageBox.Show(aa);
            }

the socketRecv() method:

public string socketRecv()
        {
            buffer = new byte[1024]; --> I think here is the problem
                        i = socket.Receive(buffer);                 
                            recibido = System.Text.Encoding.UTF8.GetString(buffer);                            
                            return recibido;     

        }

The c++ method

hFind = FindFirstFile(path.c_str(), &FindFileData);
if(hFind != INVALID_HANDLE_VALUE)
do
       {
       if(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
        {
            len = send(sock,FindFileData.cFileName,(int)strlen(FindFileData.cFileName),0);
        }
        else
        {
        }
} while(TRUE == ::FindNextFile(hFind, &FindFileData));
len = send(sock,"filemanagerstop",(int)strlen("filemanagerstop"),0);

I know that the c++ without sending the directorys/files by sockets works well, beacuse ive tried with cout.

So the problem is when the c# method shows the messages boxes, the frist shown is OK, it shows "AVG" that is my first directory.
But the second Messagebox shows ALL THE DIRECTORYS. So 2nd Messagebox: "AMD Programfiles Users etc."

I think the problem is where i writed in red color, beacuse, if i do

Bytes buffer = new byte[1024];

outside the method, in the class, the Messagebox start to show char by char, so i have thousands of Messageboxes with the chars of the directorys path.

Please help

Thanks

krosty4782 0 Light Poster

Thanks, i searched in google before making the question but i didnt find anything.

krosty4782 0 Light Poster

You were right.
The problem is that i ve benn using "System.Text.Encoding.UTF8.GetString" without the to parameters "0" and "2". For what are they ?

krosty4782 0 Light Poster

Hi!

I want to join 2 strings, but it has been impossible.
I have this:

i = socket.Receive(buffer);
 recibido = System.Text.Encoding.UTF8.GetString(buffer)

Buffer contains: "C:"

I want to add the "\\" to the string so i have tried to do:

recibido = recibido + "\\".

But no way, when y print the result it shows again "C:"
I have also tried using StringBuilder:
http://msdn.microsoft.com/en-us/library/ms228504(v=vs.80).aspx

But is the same it just print "C:"

I ve also tried changing the "\\" for any other thing like "hello"... and it still shows "C:".

krosty4782 0 Light Poster

Solved !!
I had a loop o "receive()" in other thread of other class xD

krosty4782 0 Light Poster

Yeah, socket is well open beacuse first i tried to send a string, and the string go well.

getSocket(numsock).socketSend("filemanager"); --> this is ok, beacuse server recive the string.
 Console.WriteLine(getSocket(numsock).socketRecv()); --> I will put down the method code
public string socketRecv()
        {
             buffer = new byte[1024];
                        i = socket.Receive(buffer); --> Here crash 
                        string recibido = System.Text.Encoding.UTF8.GetString(buffer);
                        return recibido;

        }
krosty4782 0 Light Poster

Hi!

Im having a problem in the next line:

i = socket.Receive(buffer)

buffer is defined as: byte[] buffer = new byte[1024];

It crash when its waiting for the answer.

In c++ im sending this:

len = send(sock,"hola",4,0);

Any idea?

Thanks

krosty4782 0 Light Poster

Hi guys.


All in FORM1

public partial class Form1 : Form
    {  
Thread thread;

public Form1()
        {
thread = new Thread(run);
            thread.Start();   
        }
public void run()
        {
          ConectadoThread socketConectado = new ConectadoThread(); 
        }
private void Form1_FormClosing(object sender, FormClosingEventArgs e)

        {    

            socketConectado.close();

        }

 }

Why when i do "socketConectado.close()" it shows me:

Error 2 The name 'socketConectado' does not exist in the current context C:\Users\Mauri\Desktop\Proyectos\Visual Studio 2008\Projects\WindowsFormsApplication3\WindowsFormsApplication3\Form1.cs

Thanks =)

krosty4782 0 Light Poster

Hi people, i have been trying a lot of codes to change a resource of a compiled exe, finally what im using is this:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;

namespace WindowsFormsApplication1
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        [DllImport("kernel32.dll", SetLastError = true)]
        static extern IntPtr BeginUpdateResource(string pFileName, bool bDeleteExistingResources);
        [DllImport("kernel32.dll", SetLastError = true)]
        static extern bool UpdateResource(IntPtr hUpdate, string lpType, string lpName, ushort wLanguage, IntPtr lpData, uint cbData);
        [DllImport("kernel32.dll", SetLastError = true)]
        static extern bool EndUpdateResource(IntPtr hUpdate, bool fDiscard);
        static unsafe void Main()
        {
            string path = "c:\\users\\sean\\desktop\\resourcer.exe";

            IntPtr hResource = BeginUpdateResource(path, false);
            if (hResource.ToInt32() == 0)
                throw new Exception("File Not Found");
  
            string newMessage = File.ReadAllText("c:\\users\\sean\\desktop\\newMessage.txt");
            Byte[] bytes = new ASCIIEncoding().GetBytes(newMessage);
            GCHandle bHandle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
            IntPtr ptr = bHandle.AddrOfPinnedObject();

            ushort id = (ushort)Language.MakeLanguageID();

            if (UpdateResource(hResource, "FILE", "message.txt", id, ptr, (uint)bytes.Length))
                EndUpdateResource(hResource, false);
            else
                MessageBox.Show("Did not update", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
    public static class Language
    {

        public static int MakeLanguageID()
        {
            CultureInfo currentCulture = CultureInfo.CurrentCulture;
            int pid = GetPid(currentCulture.LCID);
            int sid = GetSid(currentCulture.LCID); 
            return (((ushort)pid) << 10) | ((ushort)sid);
        }


        public static int GetPid(int lcid)
        { return ((ushort)lcid) & 0x3ff; }


        public static int GetSid(int lcid)
        { return ((ushort)lcid) >> 10; }

    }
}

What im doing to see if it working is to "descompress" the resource (the txt) and look if the text has change, but really not...

The code …

krosty4782 0 Light Poster

Finally what im doing is, add the exe like a resource and that exe read parameters of an ini put as resource also.
But im having a problem changing resource on the fly, im will post the problem.
Thanks

krosty4782 0 Light Poster

Yes i have seen the compiler of c# but i need another .cs.
So its the same, i need to change some parameters of that .cs from mi main app, and the compile. Its possible this ?
Thanks

krosty4782 0 Light Poster

Hello people.
Im having a problem with this.
I want to create an exe from my own exe.
For example in my exe you can put "name: " "haircolor: ". So when yo click ok, this exe make the exe2.
So when i open exe2 it shows a messagebox showing "your name is NAME and your hair color is HAIRCOLOR".
Basically, exe1 is use to configure the parameters of exe2.
Who can i do that ?
Thanks

krosty4782 0 Light Poster

I will post my code, so you can tell me if i have to use isynchronizeinvoke or what.

In Form1:

thread = new Thread(run);
thread.Start();  
   
 public void run()
        {
            socketConectado = new ConectadoThread(); 
        }

Now, i want to call a method of "socketConectado".
How can i do this?
I cant just put socketConectado.METHOD()

Thanks

krosty4782 0 Light Poster

Hi guys.
Im having a problem with this.
I have an object that i create in other thread. Now what i want to do, is that when i close my app in the event it must call a method from the object created in the thread maded earlier.
How can i do this? I ve tried calling just the object by its name but it doesnt work.
Thanks

krosty4782 0 Light Poster

I could do it !!!

I have done this:

private void conectadosView_MouseDown(object sender, MouseEventArgs e)
        {           
          if ((e.Button == MouseButtons.Right) && (conectadosView.GetItemAt(e.X, e.Y)!= null)) //If it's the right button.
            {
              
                    contextMenuStrip1.Show(this.conectadosView, e.Location);
             
            }
        }
krosty4782 0 Light Poster

Thanks for your answer Kimpl.
I ve done that and now when clicking in the listview, the contextmenu shows.
But the problem is that i want to show that menu only if he clicks in a selected item.
How can i do that ?
Thanks

krosty4782 0 Light Poster

Hi guys.
I have a question.
How i could do to display a panel of options if the cursor click in a item of the listview ?
I know about the MouseEvent and how to select the right click event, but i lost to apply that click in a item.
Thanks

krosty4782 0 Light Poster

Thanks i could do it with a tcplistener.

krosty4782 0 Light Poster

Hi all.
Im having a problem with my project.
I need that my socket recive multiple conections from differents pcs.
Example:
I have my socket, it is listening, when a pc connect to its, it stop listen, so there come the second computer trying to connect, and this computer cant doit beacuse socket isnt listening anymore.
I tried, putting the socket to listen, when anybody connects to it, the code makes another socket and it puts it in listen mode. The problem is that when i run the program there is an error and it shows that i cant have 2 sockets on the same port.
Thanks