Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27243

Error System.AccessViolationException When using .dll

$
0
0
Hello i become this Error:


A first chance exception of type 'System.AccessViolationException' occurred in Testv1.exe


When i try this Code:
Public Class Form1

Private Declare Function Sendchat Lib "C:\Users\Feet\Desktop\Projecte\Testv2\srcmd.dll" Alias "SMessage" (ByVal msg As String) As Boolean


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
On Error Resume Next
Sendchat("/tower")
End Sub

End Class




And This is the DLL Source:

#include "stdafx.h"

#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <string>
#include <fstream>
#include <float.h>
#include <tchar.h>
#include <psapi.h>
#include <tlhelp32.h>

using namespace std;

void GetProcId(char* ProcName);
DWORD ProcId = 0; // THIS IS OUR GLOBAL VARIABLE FOR THE PROC ID;

#define SAMP_DLL "samp.dll"
#define SAMP_CMP_03DR1 "C70424C97E9C8F442430"
#define SAMP_CMP_03DR2 "0074201000A30B100073"


/*#define SAMP_CMP "6A088D4C2420518D4C24"
#define SAMP_CMP "C70424C97E9C8F442430"
#define SAMP_CMP "6A088D4C2420518D4C24"
#define SAMP_CMP "5E2F060083C40CEB4B55"
#define SAMP_CMP "AE6B020080BE84010000"
#define SAMP_CMP "766A8B060FB6481451E8"*/
uint32_t g_dwSAMP_Addr = NULL;

typedef unsigned long DWORD;
DWORD dw_SAMPBaseAddress;

void Initialize();
void SendCommandToServer(char* msg);


extern "C" void __declspec(dllexport) SMessage(char* msg)
{
SendCommandToServer(msg);
};



HMODULE GetModuleHandleExtern( char *szModuleName, DWORD dwProcessId )
{
if( !szModuleName || !dwProcessId ) { return NULL; } // invalid input
HANDLE hSnap = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, dwProcessId );
if( hSnap == INVALID_HANDLE_VALUE ) { return NULL; }
MODULEENTRY32 me;
me.dwSize = sizeof( MODULEENTRY32 );
if( Module32First( hSnap, &me ) ) // we go now
{
while( Module32Next( hSnap, &me ) ) // through all modules in the target process
{
if( !strcmp( me.szModule, szModuleName ) ) // is this the model we are looking for?
{
CloseHandle( hSnap );
return me.hModule; // this is our module, return it.
}
}
}
CloseHandle( hSnap );
return NULL; // counldn't find module
}


#define FUNC_SENDCMD 0x60910
void SendCommandToServer(char* msg)
{
HWND hwWindow = FindWindow("GTA:SA:MP", NULL);

DWORD dwProcID;

GetWindowThreadProcessId( hwWindow, &dwProcID);

HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcID);


DWORD BaseAdress = (DWORD)GetModuleHandleExtern(SAMP_DLL, dwProcID);
//uint32_t samp_dll = getSampAddress();


//g_dwSAMP_Addr = ( uint32_t ) samp_dll;
uint32_t func = BaseAdress + FUNC_SENDCMD;
__asm push msg
__asm call func
}



I dont know what is wrong.....

Viewing all articles
Browse latest Browse all 27243

Trending Articles



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