[ConquerServerV2]Bug

03/31/2011 14:45 Pro4Never2#1
Hello guys, when i debug the game server is 5379 hybird's source i get this, i tryied every suggestion without any positive result , i googled it and i didn't found

[Only registered and activated users can see links. Click Here To Register...]

Translation :
Quote:
A call to PInvoke 'ConquerServer_v2! ConquerServer_v2.MSVCRT:: malloc' has unbalanced the stack. This may occur because the managed PInvoke signature does not match the target unmanaged signature. Verify that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
if someone knows the fix, he can put reply or add me on msn to fix it TeamViewer

[Only registered and activated users can see links. Click Here To Register...]


PS: i have windows xp service pack 3

PS2: i was reading the same C# file and i found things for "msvcrt.dll" so i gona to the source folder and searched for it and didn't found it at all

may this be the problem?


PHP Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
using Microsoft.Win32.SafeHandles;

namespace 
ConquerServer_v2
{
    public 
unsafe class MSVCRT
    
{
        [
DllImport("msvcrt.dll")]
        public static 
extern void* memcpy(void* dst, void* src, int length);
        [
DllImport("msvcrt.dll")]
        public static 
extern void* memset(void* dst, byte fill, int length);
        [
DllImport("msvcrt.dll")]
        public static 
extern void* malloc(int size);
        [
DllImport("msvcrt.dll")]
        public static 
extern void free(void* memblock);
        [
DllImport("msvcrt.dll")]
        public static 
extern void* realloc(void* memblock, int size);
        [
DllImport("msvcrt.dll")]
        public static 
extern int memcmp(void* buf1, void* buf2, int count);
        [
DllImport("msvcrt.dll", CharSet = CharSet.Unicode)]
        public static 
extern FILE* _wfopen(string filename, string mode);
        [
DllImport("msvcrt.dll")]
        public static 
extern void fclose(FILE* hFile);
        [
DllImport("msvcrt.dll")]
        public static 
extern void* fgets(void* u_str, int u_str_size, FILE* hFile);
        [
DllImport("msvcrt.dll")]
        public static 
extern int fgetpos(FILE* hFile, long* pos);
        [
DllImport("msvcrt.dll")]
        public static 
extern int fsetpos(FILE* hFile, long* pos);
        [
DllImport("msvcrt.dll")]
        public static 
extern int fread(void* ptr, int size, int count, FILE* hFile);
        [
DllImport("msvcrt.dll")]
        public static 
extern int fwrite(void* ptr, int size, int count, FILE* hFile);
        [
DllImport("msvcrt.dll")]
        public static 
extern int fseek(FILE* hFile, int offset, SeekOrigin origin);
    }

    public 
unsafe partial class WinMM
    
{
        [
DllImport("winmm.dll")]
        public static 
extern TIME timeGetTime();
    }

    public 
unsafe partial class Kernel32
    
{
        [
DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
        public static 
extern uint GetPrivateProfileIntW(string Section, string Key, int Default, string FileName);
        [
DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
        public static 
extern uint GetPrivateProfileStringW(string Section, string Key, string Default, char* ReturnedString, int Size, string FileName);
        [
DllImport("kernel32.dll", CharSet = CharSet.Ansi)]
        public static 
extern uint GetPrivateProfileStringA(string Section, string Key, void* Default, sbyte* ReturnedString, int Size, string FileName);
        [
DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
        [return: 
MarshalAs(UnmanagedType.Bool)]
        public static 
extern bool GetPrivateProfileStructW(string Section, string Key, void* lpStruct, int StructSize, string FileName);
        [
DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
        public static 
extern int GetPrivateProfileSectionNamesW(char* ReturnBuffer, int Size, string FileName);
        [
DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
        public static 
extern int GetPrivateProfileSectionW(string Section, char* ReturnBuffer, int Size, string FileName);
        [
DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
        [return: 
MarshalAs(UnmanagedType.Bool)]
        public static 
extern bool WritePrivateProfileStringW(string Section, string Key, string Value, string FileName);
        [
DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
        [return: 
MarshalAs(UnmanagedType.Bool)]
        public static 
extern bool WritePrivateProfileStructW(string Section, string Key, void* lpStruct, int StructSize, string FileName);
        [
DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
        [return: 
MarshalAs(UnmanagedType.Bool)]
        public static 
extern bool WritePrivateProfileSectionW(string Section, string String, string FileName);

        [
DllImport("kernel32.dll", SetLastError = true)]
        public static 
extern unsafe int WriteFile(SafeFileHandle handle, byte* bytes, int numBytesToWrite, int* numBytesWritten, IntPtr lpOverlapped);
        [
DllImport("kernel32.dll", SetLastError = true)]
        public static 
extern unsafe int ReadFile(SafeFileHandle handle, byte* bytes, int numBytesToRead, int* numBytesRead, IntPtr lpOverlapped);
        [
DllImport("kernel32.dll")]
        public static 
extern unsafe int SetFilePointer(SafeFileHandle handle, int lo, int* hi, SeekOrigin origin);
    }

    
/// <summary>
    /// The file structure implemented for the file-api functions in msvcrt.dll
    /// </summary>
    
public unsafe struct FILE
    
{
        public 
sbyte* _ptr;
        public 
int _cnt;
        public 
sbyte* _base;
        public 
int _flag;
        public 
int _file;
        public 
int _charbuf;
        public 
int _bufsiz;
        public 
sbyte* _tmpfname;
    };

    
/// <summary>
    /// Simplifies the native 4-byte sized time provided by timeGetTime()
    /// </summary>
    
public struct TIME
    
{
        private static 
TIME LastNowTime;

        public 
readonly uint Time;
        public 
TIME(uint _Value)
        {
            
Time = _Value;
        }
        public 
TIME(int _Value)
        {
            
Time = (uint)_Value;
        }
        public 
TIME AddMilliseconds(int Add)
        {
            return new 
TIME((uint)(Time + Add));
        }
        public 
TIME AddSeconds(int Add)
        {
            return new 
TIME((uint)(Time + (Add * 1000)));
        }
        public 
TIME AddMinutes(int Add)
        {
            return new 
TIME((uint)(Time + (Add * 60000)));
        }
        public 
TIME AddHours(int Add)
        {
            return new 
TIME((uint)(Time + (Add * 3600000)));
        }
        public 
override string ToString()
        {
            return 
Time.ToString();
        }
        public 
override int GetHashCode()
        {
            return (int)
Time;
        }
        public static 
TIME Parse(string str)
        {
            return new 
TIME(uint.Parse(str));
        }

        public static 
TIME Now
        
{
            
get
            
{
                
TIME now = WinMM.timeGetTime();
                if (
LastNowTime.Time >= now.Time)
                    throw new 
ApplicationException("timeGetTime() has been reset.");
                return 
now;
            }
        }
    }

    
/// <summary>
    /// Exposes a keep-alive pointer to the managed world.
    /// Pointer created with malloc(), freed with free(), realloced with realloc().
    /// </summary>
    
public unsafe class SafePointer
    
{
        private 
bool freed;
        private 
byte* m_Addr;
        private 
int m_MemoryInBytes;
        public 
byte* Addr { get { return m_Addr; } }
        public 
int MemoryInBytes { get { return m_MemoryInBytes; } }

        public 
SafePointer(int Size)
        {
            
m_Addr = (byte*)MSVCRT.malloc(Size);
            
MSVCRT.memset(m_Addr, 0, Size);
            
m_MemoryInBytes = Size;
            
freed = false;
        }
        public 
void Realloc(int Size)
        {
            
m_Addr = (byte*)MSVCRT.realloc(m_Addr, Size);
            
MSVCRT.memset(m_Addr, 0, Size);
            
m_MemoryInBytes = Size;
            
freed = false;
        }
        public 
void Free()
        {
            if (!
freed)
            {
                
MSVCRT.free(Addr);
                
freed = true;
            }
        }
        ~
SafePointer()
        {
            
Free();
        }
    }

    
/// <summary>
    /// Implements support to existing .NET classes to allows them to interact
    /// with native functions, and actions more easily
    /// </summary>
    
public static unsafe class NativeExtended
    
{
        public static 
void CopyTo(this string s, void* pDest)
        {
            
byte* Dest = (byte*)pDest;
            for (
int i = 0; i < s.Length; i++)
            {
                
Dest[i] = (byte)s[i];
            }
        }
        public static 
bool CheckBitFlag(this uint value, uint flag)
        {
            return ((
value & flag) == flag);
        }
    }
} 
03/31/2011 23:26 Korvacs#2
The fix has been posted before, search please.
04/01/2011 12:34 Pro4Never2#3
hmmm, i searched yesterday , and i researched today, and unfortunatly i couldn't, some good ppl posted some suggestions on the old thread and no one worked
04/01/2011 12:56 Korvacs#4
Took me all of 10 seconds to find using search.

[Only registered and activated users can see links. Click Here To Register...]
04/01/2011 15:35 Syst3m_W1z4rd#5
Quote:
Originally Posted by Korvacs View Post
The fix has been posted before, search please.
He would need to switch the blowfish etc. out then. That won't fix it at all. The libraries is from C++.
He just need to force it as 32bit I think.
04/01/2011 16:05 Korvacs#6
Quote:
Originally Posted by Syst3m_W1z4rd View Post
He would need to switch the blowfish etc. out then. That won't fix it at all. The libraries is from C++.
He just need to force it as 32bit I think.
Read the god damn error message, then read the thread i posted:

Quote:
A call to PInvoke 'ConquerServer_v2! ConquerServer_v2.MSVCRT:: malloc' has unbalanced the stack. This may occur because the managed PInvoke signature does not match the target unmanaged signature. Verify that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
The hell is wrong with people these days?
04/01/2011 16:14 Syst3m_W1z4rd#7
I know, but if he replace it it won't help anyways. He would have to recode some things in the source.
04/01/2011 17:15 Korvacs#8
It will fix his current problem >_>"
04/02/2011 15:52 Pro4Never2#9
okay, i put the project x86 (32bit) and i debugged, i got the same error , so it's not a 32/64bit problem, it can't be from appserv or navicat but the source is not SQL, so from where
04/03/2011 11:26 Korvacs#10
Did you change the calling conventions for all of your dll imports like i suggest in that thread?
08/10/2011 10:45 EgyWolf#11
same prb here