[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 voidmemcpy(voiddstvoidsrcint length);
        [
DllImport("msvcrt.dll")]
        public static 
extern voidmemset(voiddstbyte fillint length);
        [
DllImport("msvcrt.dll")]
        public static 
extern voidmalloc(int size);
        [
DllImport("msvcrt.dll")]
        public static 
extern void free(voidmemblock);
        [
DllImport("msvcrt.dll")]
        public static 
extern voidrealloc(voidmemblockint size);
        [
DllImport("msvcrt.dll")]
        public static 
extern int memcmp(voidbuf1voidbuf2int count);
        [
DllImport("msvcrt.dll"CharSet CharSet.Unicode)]
        public static 
extern FILE_wfopen(string filenamestring mode);
        [
DllImport("msvcrt.dll")]
        public static 
extern void fclose(FILEhFile);
        [
DllImport("msvcrt.dll")]
        public static 
extern voidfgets(voidu_strint u_str_sizeFILEhFile);
        [
DllImport("msvcrt.dll")]
        public static 
extern int fgetpos(FILEhFilelongpos);
        [
DllImport("msvcrt.dll")]
        public static 
extern int fsetpos(FILEhFilelongpos);
        [
DllImport("msvcrt.dll")]
        public static 
extern int fread(voidptrint sizeint countFILEhFile);
        [
DllImport("msvcrt.dll")]
        public static 
extern int fwrite(voidptrint sizeint countFILEhFile);
        [
DllImport("msvcrt.dll")]
        public static 
extern int fseek(FILEhFileint offsetSeekOrigin 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 Sectionstring Keyint Default, string FileName);
        [
DllImport("kernel32.dll"CharSet CharSet.Unicode)]
        public static 
extern uint GetPrivateProfileStringW(string Sectionstring Keystring Default, charReturnedStringint Sizestring FileName);
        [
DllImport("kernel32.dll"CharSet CharSet.Ansi)]
        public static 
extern uint GetPrivateProfileStringA(string Sectionstring Keyvoid* Default, sbyteReturnedStringint Sizestring FileName);
        [
DllImport("kernel32.dll"CharSet CharSet.Unicode)]
        [return: 
MarshalAs(UnmanagedType.Bool)]
        public static 
extern bool GetPrivateProfileStructW(string Sectionstring KeyvoidlpStructint StructSizestring FileName);
        [
DllImport("kernel32.dll"CharSet CharSet.Unicode)]
        public static 
extern int GetPrivateProfileSectionNamesW(charReturnBufferint Sizestring FileName);
        [
DllImport("kernel32.dll"CharSet CharSet.Unicode)]
        public static 
extern int GetPrivateProfileSectionW(string SectioncharReturnBufferint Sizestring FileName);
        [
DllImport("kernel32.dll"CharSet CharSet.Unicode)]
        [return: 
MarshalAs(UnmanagedType.Bool)]
        public static 
extern bool WritePrivateProfileStringW(string Sectionstring Keystring Valuestring FileName);
        [
DllImport("kernel32.dll"CharSet CharSet.Unicode)]
        [return: 
MarshalAs(UnmanagedType.Bool)]
        public static 
extern bool WritePrivateProfileStructW(string Sectionstring KeyvoidlpStructint StructSizestring FileName);
        [
DllImport("kernel32.dll"CharSet CharSet.Unicode)]
        [return: 
MarshalAs(UnmanagedType.Bool)]
        public static 
extern bool WritePrivateProfileSectionW(string Sectionstring Stringstring FileName);

        [
DllImport("kernel32.dll"SetLastError true)]
        public static 
extern unsafe int WriteFile(SafeFileHandle handlebytebytesint numBytesToWriteintnumBytesWrittenIntPtr lpOverlapped);
        [
DllImport("kernel32.dll"SetLastError true)]
        public static 
extern unsafe int ReadFile(SafeFileHandle handlebytebytesint numBytesToReadintnumBytesReadIntPtr lpOverlapped);
        [
DllImport("kernel32.dll")]
        public static 
extern unsafe int SetFilePointer(SafeFileHandle handleint lointhiSeekOrigin 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 
bytem_Addr;
        private 
int m_MemoryInBytes;
        public 
byteAddr get { return m_Addr; } }
        public 
int MemoryInBytes get { return m_MemoryInBytes; } }

        public 
SafePointer(int Size)
        {
            
m_Addr = (byte*)MSVCRT.malloc(Size);
            
MSVCRT.memset(m_Addr0Size);
            
m_MemoryInBytes Size;
            
freed false;
        }
        public 
void Realloc(int Size)
        {
            
m_Addr = (byte*)MSVCRT.realloc(m_AddrSize);
            
MSVCRT.memset(m_Addr0Size);
            
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 svoidpDest)
        {
            
byteDest = (byte*)pDest;
            for (
int i 0s.Lengthi++)
            {
                
Dest[i] = (byte)s[i];
            }
        }
        public static 
bool CheckBitFlag(this uint valueuint 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