1,075,991 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

Posts by wlalth

I need to return byte array from the function, in your dllimport statement, method_4 have one argument which has ref int type. Is it possible to create byte array with ref type? Also on readprocessmemory byte array argument defined without ref:

        [DllImport("kernel32.dll")]
        public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,
        byte[] lpBuffer, UIntPtr nSize, ref uint lpNumberOfBytesWritten);

Im little confused, also im not sure my problem is with my .net part or native part. I can succesfully call my native functions from my native dlls, however im not able to return arrays from them. Of course there is another methods to do that, what but i want to learn that way.

wlalth
Newbie Poster
13 posts since Jun 2010
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

Hi, how can i return arguments in my custom native dll like ReadProcessMemory api?

For example for readprocessmemory, byte arguments return readed value. Its mixed c# and c++ so if its wrong place to ask, sorry about that.

       public byte[] ByteOku(uint BellekAdresi, int PID)
        {
            IntPtr readHandle = NativeMethods.OpenProcess(0x10, false, (uint)PID);
            byte[] bytes = new byte[50];
            uint rw = 0;
            NativeMethods.ReadProcessMemory(readHandle, (IntPtr)BellekAdresi, bytes, (UIntPtr)50, ref rw);
            return bytes;
        }





[DllImport("test.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
public static extern void method_4(byte[] buffer);


private void button1_Click(object sender, EventArgs e)
        {
            byte[] b = new byte[] { 0x5D, 0x0, 0x0, 0x0, 0x0 };
            method_4(b);
                 MessageBox.Show(b[0].ToString() + "   " + b[1].ToString() + "   " + b[2].ToString() +  "   " + b[3].ToString());

        }   

//in dll which is written in c++ mfc        

extern "C" __declspec(dllexport) void method_4(int buffer[])
{
        buffer[1] = 0x5;
        buffer[2] = 0x5;
        buffer[3] = 0x5;
        buffer[4] = 0x5;
}

but buffer array is not modified on button1_click

wlalth
Newbie Poster
13 posts since Jun 2010
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

Hi, i have a stange problem with a my patch system. If two of the files are not exist on the users computer, patcher downloads them perfectly.

If first file exist and different from the web site, patcher also downloads it perfectly. However, if the second file are exist on users computer and its different from the file which is uploaded on website, patcher don't downloads it. Download function triggered and overwrite on file but download wasn't start.

Its completely my system, so maybe it is not the best way for the make a updater.

What is wrong is following code?

ps. sorry for message boxes i don't translate them, but i think thats no matter.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Diagnostics;
using System.Timers;
using System.Security;
using System.Security.Cryptography;
using System.Threading;




namespace update_final
{
    public partial class Form1 : Form
    {
        int x = 1;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.ControlBox = false;
            guncelle();

        }

        private bool denetle(string dosyaismi, string dosyayolu)
        {
            string netdboyu = "0";
            string userdboyu = "0";

            WebClient bak = new WebClient();

            try        // bakalim boyle bir dosya var mi???
            {

                FileInfo userdosya = new FileInfo(dosyaismi);
                userdboyu = userdosya.Length.ToString();
            }

            catch (FileNotFoundException)
            {
                return true; // yokmuş o zaman indir

            }


            try // bakalım nete erişebiliyo muyuz???
            {
                WebRequest requ = HttpWebRequest.Create(dosyayolu + dosyaismi);
                requ.Method = "HEAD";

                WebResponse resu = requ.GetResponse();
                netdboyu = resu.ContentLength.ToString();

            }

            catch (SystemException)
            {         
                return false; // erişemedik bu dosyayı atlayıver
            }

            if (userdboyu == netdboyu)
            {
                return false;
            }

            else
            {
                return true;
            }


        }
        

        private void indir(string neyi, string nerden)
        {
            System.Threading.Thread.Sleep(1000);
            label1.Text = "Güncellenen dosya: " + neyi;
            WebClient indir = new WebClient();
            indir.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
            indir.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
            indir.DownloadFileAsync(new Uri(nerden + neyi), (neyi));
        }



        private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            progressBar1.Value = e.ProgressPercentage;
        }


        private void Completed(object sender, AsyncCompletedEventArgs e)
        {
            x++;
            guncelle();
        }


        private void guncelle()
        {
            switch (x)
            {
                case 1:
                    if (denetle("file 1", "http://mysitegoeshere/") == true)
                    {
                        indir("file 1", "http://mysitegoeshere/");
                    }

                    else
                    {
                        x++;
                        guncelle();
                    }

                    break;
                case 2:
                    if (denetle("file 2", "http://mysitegoeshere/") == true)
                    {
                        indir("file 2", "http://mysitegoeshere/");
                    }

                    else
                    {
                        x++;
                        guncelle();
                    }
                    break;

                case 3:
                    System.Threading.Thread.Sleep(2000);
                    calistir("file 1"); // main exe of my program
                    Application.Exit();
                    break;

            }

        }


        private void calistir(string neyi)
        {
            Process firot = new Process();
            try
            {
                firot.StartInfo.FileName = neyi;
                firot.Start();
            }


            catch (FileNotFoundException)
            {
                MessageBox.Show("Kurulum hatalı yapılmış. Lütfen güncelleme modülünü tekrar çalıştırın");

            }

            catch (System.ComponentModel.Win32Exception)
            {
                MessageBox.Show("Kurulum hatalı yapılmış. Lütfen güncelleme modülünü tekrar çalıştırın");
            }

            Close();
        }


    }


}
wlalth
Newbie Poster
13 posts since Jun 2010
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

Well i try lot of function of System.Diagnostics. Problem is all information which is get by this class is can be edited easily by hex editors.

Im also trying the FileVersionInfo and getting hashcodes of .exe of running programs, but result is same.

Process.Id is meaningles for this program because it is not depended on applications build.

My aim is how can i define a running application without changeble data. For example using hex editor i can edit winamps window title, company name etc. How can i understand these running application is winamp?

Processexplorer can show the strings of running processes. Is there class or dllimport to access them? Im posting a picture to show what i mean.

http://img693.imageshack.us/img693/4151/pxp.jpg

wlalth
Newbie Poster
13 posts since Jun 2010
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

Hi, i wrote a patch system. It check the links and download them, if the files not same with the users files.

All steps are working, i have only one problem. First download is perfectly complated, but when DownloadFileAsycn fired second times, its don't work. It creates strange file of 0 bytes, with name of second file.

Im posting a part of my codes.

progressBar1.Value = 0;
            string netdboyu = "0";
            string userdboyu = "0";
            string webdizin = "my url is here";
            


            WebClient indir = new WebClient();
            indir.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
            indir.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
indir.DownloadFileAsync(new Uri(webdizin + filename), (filename));// filename is parameter of function.

These codes are under a function. When download process complated im calling it again, im using switch function before called. With that, my update function is trying to download the correct file. But can't download.

wlalth
Newbie Poster
13 posts since Jun 2010
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

Im already done similar thing to that. But i want to sending keys to non active windows, without active them.

wlalth
Newbie Poster
13 posts since Jun 2010
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

Any data will be useful, which is not same with other applications.

For example: hashcodes, company names etc. Now i can get them and there are very useful about analyzing running processes.

But im sure there are other ways to analyze running applications

wlalth
Newbie Poster
13 posts since Jun 2010
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

Hi, im working on basic macro program. I want to select applications by window name and sending keys(f5 f1 etc.) to them basically.

The problem is, sendkeys dont work on non-active windows. I search for this problem internet.

I can get window names to combobox with;

foreach (Process FFget in Process.GetProcesses())
{
    if (FFget.MainWindowTitle.Length>1)
    {
         comboBox1.Items.Add(FFget.MainWindowTitle.ToString());                  
    }
}

Now i can select window, which is i want to sending keys. I can get any information about windows from FFget.

Im also found a basic function, which is using keybd_event.

private void Presskey(byte keyCode)
{          
  const int KEYEVENTF_EXTENDEDKEY = 0x1;
  const int KEYEVENTF_KEYUP = 0x2;
  keybd_event(keyCode, 0x45, KEYEVENTF_EXTENDEDKEY, 0);
  keybd_event(keyCode, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
}

With that i can send to keys to activate window.

Now question is how can i sending keys to non-active window.

Im found examples for delphi, but there is no for c#.

wlalth
Newbie Poster
13 posts since Jun 2010
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

You can add stuff which is not InitializeComponent(); to Form1_Load.

public Form1()
{
   InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
    string[] _args = Environment.GetCommandLineArgs();
    if (_args.Contains("options"))
    {
        this.Show();
    }
}
wlalth
Newbie Poster
13 posts since Jun 2010
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

Now working perfect, thanks.

wlalth
Newbie Poster
13 posts since Jun 2010
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0
foreach (Control a in this.Controls)
{
   if (a is ComboBox)
   {
      a.Items.Add(" ");
      a.Items.Add("F1");
   }
}

Thanks, now MessageBox triggered. But i cant adding items to ComboBox. Items are giving following error:

'System.Windows.Forms.Control' does not contain a definition for 'Items' and no extension method 'Items' accepting a first argument of type 'System.Windows.Forms.Control' could be found (are you missing a using directive or an assembly reference?)

wlalth
Newbie Poster
13 posts since Jun 2010
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

Solved: foreach ComboBox in C#

foreach (ComboBox a in Form1.ActiveForm.Controls)
{
  MessageBox.Show("hello");
}

Hi, i want to add same items to all ComboBoxes, expect one. The part of my code is here. The problem is foreach loop never fire. I never see the MessageBox which is saying "hello". What is wrong in my code?

Thanks.

wlalth
Newbie Poster
13 posts since Jun 2010
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0

Hi. I need to get unique information of runnig programs. I dont want to get ProcessName or MainWindowTitle. Because im working on anti-cheat program.

Im tried lot of method of GetProcess() but any of them give me the uniq. information.

So is it possible to get uniq data of running programs with c#?

Thanks.

wlalth
Newbie Poster
13 posts since Jun 2010
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0
 
© 2013 DaniWeb® LLC
Page rendered in 0.0860 seconds using 2.55MB