Page 1 of 1

Managed Code in Unmanaged C++

Posted: Sat Jan 05, 2008 12:27 am
by LuxuriousMeat
I followed Microsofts instructions, but when I compile my un-managed C++ project and it imports my type library it find a **** load of errors and it fails to build. Has anyone ever done this before that can help me?
The error's are like this:

Code: Select all

IO.tlb stray '\255' in program
Instructions for it can be found here:
http://support.microsoft.com/kb/828736

Here's my code I'm compiling into a type library:

Code: Select all

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace IO
{
    public class ReaderWriter : IReaderWriter
    {
        public int GetInt32(string path, int offset)
        {
            BinaryReader br = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite));
            if ((br.BaseStream.Length - 4) >= offset)
            {
                br.BaseStream.Position = offset;
                int ret = br.ReadInt32();
                br.Close();

                return ret;
            }
            return -1;
        }
    };

    public interface IReaderWriter
    {
        int GetInt32(string path, int offset);
    };
}

Posted: Sat Jan 05, 2008 9:48 am
by Evan
Your trying to compile that with C++?
Give me some more info on what your doing and I might be able to help.
Or get on AIM.

Posted: Sat Jan 05, 2008 12:59 pm
by LuxuriousMeat
Look at the link, I did exactly that. I compiled it into a .dll in C# and used the Visual Studio Command prompt to convert it into a .tlb (type library). And I did a import statement in my unmanaged C++ project like this:

Code: Select all

#import "IO.tlb" raw_interfaces_only

Posted: Sat Jan 05, 2008 2:12 pm
by xzodia
im fairly sure its impossible to import managed code into unmanaged code...

Posted: Sat Jan 05, 2008 2:23 pm
by LuxuriousMeat
Look at the link I posted...

Posted: Sat Jan 05, 2008 4:47 pm
by xzodia
>_>
<_<
i stand corrected... :P

Posted: Sat Jan 05, 2008 5:43 pm
by LuxuriousMeat
Never mind guys, I fixed it :D.