Thanks for the comments. My executable contains data to create a DVD movie. Its something like packing all data inside the executable and on execution it creates a DVD movie with the data it hosts. Its not a setup exe. I cannot put the data in seperate files. It has to be one single executable. :( When the exe was 2 GB, it didn't issue any sys warning or error message, but a application error saying the header could not be read. I think the Loader didnot create the executable fully/properly. But with 1.5 GB data, it worked fine. Vini
Vini Deep
Posts
-
Size of an executable -
Image EditorHi all, Does anybody know how image editors are made.I dont mean the image manipulation part ,but the canvas like thing we see in ms paint on which we draw ,erase .draw lines etc....I dont think it is a dilog.It would rather be a window , a paint window but how do we maintain it.say loading am image to a window is simple and i prefer the IPicture and IStream way of the win32 sdk.Once the image is loaded ,i even managed to draw on it ,like using moveto and line functions from the gdi.But the real trouble is how would i store the image temporarily.Say i have the image read from the file into the IStream and enclosed by IPicture .I render this from the IPicture to the window.Now i draw some lines over the image.Technically the dc is modified.Now how would i extract this modified dc into a buffer and latter on store it to a file.One suitable way is to Create a compatible dc and bitmap make a snapshot of this window,but it is not good,the image is not clear .How would i go around this situation. Please help. Vini
-
Extracting video frame from MJPEG AVIHi, I want to extract a frame from an Motion JPEG avi file. Can anyone help me. Is there any link which gives me an info on the file format for the video data in the avi. I'm able to extract the header from the avi file in BITMAPINFOHEADER struct, and then read the avi property. How are the video frames stored? is it as JPGs or BMPs in Motion Jpeg Avi? I don't want to use the API's available. Kindly help. Vini
-
Windows Messag handling in C#Hi, Is there any C# equivalent for SDK function 'MsgWaitForMultipleObjects()'? I want to implement this following c++ code in c#. Which is the right path to follow.
bool CMyClass::MyFun() { unsigned threadID; DWORD waitResult; MSG msg; writeSuccess = false; hThread = (HANDLE)_beginthreadex(NULL, 0,writeThread, NULL,0,&threadID); if (!hThread) return false; waitResult = MsgWaitForMultipleObjects(1, &hThread, FALSE, INFINITE, QS_ALLINPUT); while (waitResult != WAIT_OBJECT_0) { if (waitResult == WAIT_OBJECT_0 + 1) while (PeekMessage(&msg, NULL,0,0,PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } if (waitResult == WAIT_FAILED) { //An error occured, we need to handle it here break; } waitResult = MsgWaitForMultipleObjects(1, &hThread, FALSE, INFINITE, QS_ALLINPUT); } CloseHandle(hThread); hThread = NULL; return writeSuccess; }
I have read about the
IMessageFilter
interface ofMicrosoft.Win32
namespace. Is this the right way to proceed on this. Kindly advise. Vini -
Calling an exported Function - Issue with different calling convention in C#Tnx. I have seen that previous post of yours before. I am able to call the exported class methods. The issue with callback function, I think I have it right now, is by modifying the C++ DLL source. Added the __stdcall to the Callback method declaration. Is this okay?
bool mapImage(UINT16 iSectorSize, bool (__stdcall * pCallback)(UINT32, UINT8 *, bool))
Tnx for the help. Vini
-
Calling an exported Function - Issue with different calling convention in C#Heath Stewart wrote: You can actually P/Invoke class methods so long as you have a class factory to create an instance of that class. Is there any link that explains this? I cannot change the calling convention as the method exported is a member of the class and I need to pass the instance ptr of the class as the first argument to the method, to call the class methods. Is there any other way to call the class methods from the DLL? Will it help, if I change the callback method declaration in the C++ Dll to something else? like,
bool mapImage(UINT16 SectorSize, bool (* __stdcall CallbackFunctionAddress)(UINT32 SectorToBeRead, UINT8 * SetToSectorData, bool IsLiteral));
To call the methods from the exported class, I have added two methods to the class: 1. To return the instance ptr of the class to the client and 2. To remove the instance of the class. Is this the correct way? Pls help... :confused: Vini
-
Calling an exported Function - Issue with different calling convention in C#Hi, I have 2 methods exported from a dll, MyReader.dll
typedef unsigned short UINT16; typedef unsigned int UINT32; typedef unsigned char UINT8; #define CMYREADER_API __declspec(dllexport) class CMYREADER_API CMyReader { public: bool mapImage(UINT16 SectorSize, const char * FileOnHardDriveToMap); bool mapImage(UINT16 SectorSize, bool (* CallbackFunctionAddress)(UINT32 SectorToBeRead, UINT8 * SetToSectorData, bool IsLiteral)); .... };
How can I call the 2nd method from My C# Client? I have declared a delegate to pass as the 2nd argument to the function.
[DllImport("MyReader.dll", EntryPoint ="?mapImage@CMYReader@@QAE_NGP6A_NIPAE_N@Z@Z",CallingConvention=CallingConvention.ThisCall)] private static extern System.Int32 mapImage(IntPtr inst,System.UInt16 SectorSize, ReadSectorDelegate CallbackFunctionAddress);
But when I give the CallingConvention as
CallingConvention.ThisCall
, I get the following error.--------------------------- Microsoft Visual C++ Debug Library --------------------------- Debug Error! Program: E:\Vini\MyRdrTest\bin\Debug\MyRdrTest.exe Module: File: i386\chkesp.c Line: 42 The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention. (Press Retry to debug the application) --------------------------- Abort Retry Ignore ---------------------------
But if I change the callingConvention to**CallingConvention.StdCall**
, it does not call the CallBack function. Is there any other way to implement this? What am I doing wrong here? Kindly help. Vini -
Marshaling the structure array member of Structure in C#Thank You very much... :rose: Finally I think I am getting everything right. I used the method of pinning the first structure , which u mentioned in one of your previous post. Tnx a lot. cheers :) Vini
-
Marshaling the structure array member of Structure in C#Thanks. But my function eventhough declared as a call back, is called by the UI. I already have a c++ client which uses this dll and calls the said function. I am trying to build a similar client in C#. As far as writing another method is concerned, I have got only the .dll file and the .h file with me. source code is not available. I have used the depends.exe, which shows me an entry to the above mentioned function as _MyFunc@4 in the dll. Any idea?? Vini
-
Marshaling the structure array member of Structure in C#Sorry about this. I very much appretiate your help :rose:. Still a basic doubt: Heath Stewart wrote:
[StructLayout(LayoutKind.Sequential)]
public struct FirstStruct
{
[MarshalAs(UnmanagedType.R4)] public double XSpeed;
[MarshalAs(UnmanagedType.SysInt)] public IntPtr DRate;
[MarshalAs(UnmanagedType.SysUInt)] public IntPtr RotCtrl;
// ctor added for convenience and example.
public FirstStruct(double XSpeed, long DRate, long RotCtrl)
{
this.XSpeed = XSpeed;
this.DRate = new IntPtr(DRate);
this.RotCtrl = new IntPtr(RotCtrl);
}
}Is there any problem if I declare the structure as
[StructLayoutAttribute(LayoutKind.Sequential)] public struct FirstStruct { public System.Double XSpeed; public System.Int32 DRate; public System.UInt32 RotCtrl; }
If I want to call a function from a dll written in C++ from my c# client, what should I do? Should I create a similar C# structure with managed DataTypes and use that to call the c++ dll function from my C# client, then use it to get the values returned by the Dll**OR**
Should I create a similar structure in C# with Unmanaged Type data and then pass it to the function exported by the Dll and use the values returned? Is the above both declaration one and the same? I have used[MarshalAs(UnmanagedType.ByValTStr, ....)]
only in places where the variable declared was char[].[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 12)] public string Vendor;
When I debug the program, at the function call I get an
'ExecutionEngineException'
. Is it the problem which the marshaling of the structure array? Kindly help. Vini -
Marshaling the structure array member of Structure in C#Thanks.. Couldn't quite get it correct. The structure is passed to the function in dll as reference. If I declare the structure array variable as IntPtr, should I use pointer arithematics to read the value back from the structure array member of the struct? Tnx :) Vini
-
C++ Bit Fields implementation in C#I got it with BitVector32
BitVector32.CreateSection Method
and get/set methods. Thanks :rose: Vini -
C++ Bit Fields implementation in C#Hi, I have a structure declared with bit fields in one of the C++ dll I am calling in my c# application. How can I change it to C# type struct?
typedef unsigned int UINT32; typedef struct DEV_TYPE { UINT32 ReadCdR :1; UINT32 ReadCdRw :1; UINT32 ReadDvdRom :1; UINT32 ReadDvdRam :1; UINT32 ReadDvdMinusR :1; UINT32 ReadDvdMinusRw :1; UINT32 ReadDvdPlusR :1; UINT32 ReadDvdPlusRw :1; UINT32 WriteCdR :1; UINT32 WriteCdRw :1; UINT32 Reserved0 :1; UINT32 WriteDvdRam :1; UINT32 WriteDvdMinusR :1; UINT32 WriteDvdMinusRw:1; UINT32 WriteDvdPlusR :1; UINT32 WriteDvdPlusRw :1; UINT32 TapeDrive :1; UINT32 Reserved :15; } DEV_TYPE;
I have read in MSDN that C# does not support bit fields. Is there any method to implement this structure in C#? Pls help.. Thanks Vini
-
Marshaling the structure array member of Structure in C#Heath Stewart wrote: // Define the callback.[return: MarshalAs(UnmanagedType.SysUInt)]public delegate IntPtr MyFunc(ref SecondStruct Info); This should work. Thanks Very much. But I am not fully clear.
__declspec (dllexport) unsigned int CALLBACK MyFunc(SEC_STRUCT * Info);
This is the function exported by the C++ Dll. How should I call this function from my C# client?[DllImport("MyDll",CallingConvention=CallingConvention.Cdecl)] public extern static System.UInt32 MyFunc(ref SecondStruct Info) ; private void button1_Click(object sender, System.EventArgs e) { FirstStruct[] first= new FirstStruct[40]; ... SecondStruct info = new SecondStruct(....,first,...); System.UInt32 uRet= MyFunc(ref info); MessageBox.Show(info.Model); ... }
Is this code correct? How to marshal the SecondStruct to IntPtr using
Marshal.StructureToPtr
and back usingMarshal.PtrToStructure
? Pls Help. Thanks :rose: Vini -
Marshaling the structure array member of Structure in C#Heath Stewart wrote: What was the full message of the exception? An unhandled exception of type 'System.TypeLoadException' occurred in MyProj.exe Additional information: Can not marshal field CrwWrd of type FIRST_STRUCT: This type can not be marshaled as a structure field. kindly help.. Vini
-
Marshaling the structure array member of Structure in C#Hi, I have a structure defined in a dll which has another structure array as a member. I need to call this Dll from C#. How do I do it? This is the structure I have in the DLL. typedef struct FIRST_STRUCT { double XSpeed; int DRate; unsigned int RotCtrl } FIRST_STRUCT; typedef struct SEC_STRUCT { char Model[20]; unsigned int SuptTxt; FIRST_STRUCT CurSpd; FIRST_STRUCT MaxRdSpd; unsigned int cNumSpd; FIRST_STRUCT CrwWrd[40]; FIRST_STRUCT DWrd[20]; } SEC_STRUCT; __declspec (dllexport) unsigned int CALLBACK MyFunc(SEC_STRUCT * Info); _________________________________________________________________________ How do I call this from my C# client? I have changed the structure as [StructLayoutAttribute(LayoutKind.Sequential)] public struct First_struct { public System.Double XSpeed; public System.Int32 DRate; public System.UInt32 RotCtrl; } How do I marshal the SEC_STRUCT in C#. I tired using the MarshalAs(), but it gave me a run time error 'System.TypeLoadException' [MarshalAs(UnmanagedType.ByValArray, SizeConst = 40)] public First_struct[] CrwWrd; Kindly Help. Thanks Vini
-
Accessing C++ classes from within C# .NETlajiyo wrote: I think you can modify the dll if you have the source code. you can modify the functions which you want to dllimport. for example you can do "export c mapImage()" The mapImage() function is a member function of a class and the class is already declared as '__declspec(dllexport)'. But to access the class in my Client, I have created a class derived from 'IDisposable' and declared a member 'private IntPtr inst' to get the access to the exported class. Then the calling convention i need to use is 'ThisCall', isn't? How to remove the exception? Hope you meant extern "C" or is it 'export c' ? :confused: Vini
-
Accessing C++ classes from within C# .NETHi, I have an unmanaged C++ DLL which exports certain classes. I want to access these classes from the C# client. I was able to do so by modifying the DLL source to export class creation and destruction functions. Is this the only option for the problem? If I don't have the source code for the DLL, but just the .dll file, how can i access the exported methods from the dll, in C# client? Also, I have read somewhere about writing a Wrapper class for the DLL, in C#. Is it possible to write the wrapper in C#? Is there any link which will help me in this? In my c# client , for DllImport, i have given the callingConvention as 'CallingConvention.ThisCall'. One of my exported function has a callBackFunction as argument. I declared a delegate to take care of this. But when executed, the application gives an error of "different calling convention used". If I change the CallingConvention to 'StdCall' or 'cdecl', there is no error, but then the call back function is not called. [DllImport("ediImgReader - Debug.dll", EntryPoint ="?mapImage@Cedi9660Reader@@QAE_NGP6A_NIPAE_N@Z@Z",CallingConvention=CallingConvention.ThisCall )] private static extern System.Int32 mapImage(IntPtr inst,System.UInt16 SectorSize, ReadSectorDelegate CallbackFunctionAddress); public delegate System.Int32 ReadSectorDelegate(System.UInt32 SectorToBeRead,System.Byte SetToSectorDataIsLiteral, System.Int32 IsLiteral); public static System.Int32 ReadSector(System.UInt32 SectorToBeRead,System.Byte SetToSectorDataIsLiteral, System.Int32 IsLiteral) { MessageBox.Show("Inside Delegate"); return 1; } public static System.Int32 mapImage(System.UInt16 SectorSize, ReadSectorDelegate CallbackFunctionAddress) { mapImage(Instance.inst,SectorSize,CallbackFunctionAddress); return 1; } Kindly help. Thanks.. Vini
-
Calling a class exported by a custom DLL in C#Hi, I have a custom dll in C++ which exports a class with certain member functions. I want to call the methods from a c# application. I am able to call the member functions seperately using the DllImports[....]. Is it possible to instantiate an object of the exported class from the C# tester application? Kindly help. Is there any link which would give me this detail. Is the source code of the DLL necessary for this. Thanks, Regards, Vini
-
Converting and Calling C++ DLL in C#Hi, I am new to C# programming. I want to refer a DLL written in C++ (win32 DLL) in an application in C#. The Dll is in unmanaged code and my tester application is a C# application. I have read somewhere about using tlbimp to generate the metadata file. Can anyone tell me the process or any link which gives me information on this. Kindly help. Thanks Vini