473,385 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Need help understanding how to call unmanaged dll

I bought a USB IR reciever and installed the driver. The developer
kit gives a DLL with the following information:
C++ Builder / Microsoft Visual C++:

#ifdef __cplusplus
extern "C" {
#endif

int __stdcall DoGetInfraCode(uchar * code, int extra, int *
codeLen);

#ifdef __cplusplus
}
#endif

So in my C# project I have done this:

public class IgorUSB
{
[DllImport("IgorUSB.dll")]
public static extern int DoGetInfraCode(ref byte[] code, int
extra, ref int codeLen);
}
Which I assume it the correct way to define the wrapper to the dll.

Next I added this to my Windows Form:

private void Form1_Load(object sender, EventArgs e)
{
byte[] code = new byte[12];
int extra = 0;
int len = 0;
IgorUSB.DoGetInfraCode(ref code, extra, ref len);
}

But I get the following error when I run it:

"LoaderLock was detected
Message: Attempting managed execution inside OS Loader lock. Do not
attempt to run managed code inside a DllMain or image initialization
function since doing so can cause the application to hang."

Does my code look correct? The only thing I can think of is the when
this DLL is loaded it pops up a message box. Could that be the
problem?

Feb 3 '07 #1
3 2368
int __stdcall DoGetInfraCode(uchar * code, int extra, int *
>codeLen);

#ifdef __cplusplus
}
#endif

So in my C# project I have done this:

public class IgorUSB
{
[DllImport("IgorUSB.dll")]
public static extern int DoGetInfraCode(ref byte[] code, int
extra, ref int codeLen);
}
Which I assume it the correct way to define the wrapper to the dll.

You should remove the ref modifier on the first parameter.

Not sure why that would cause a loader lock error though.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Feb 3 '07 #2
Hi,

"mjohnson" <cr****@hotmail.comwrote in message
news:11*********************@v45g2000cwv.googlegro ups.com...
>
But I get the following error when I run it:

"LoaderLock was detected
Message: Attempting managed execution inside OS Loader lock. Do not
attempt to run managed code inside a DllMain or image initialization
function since doing so can cause the application to hang."

Does my code look correct? The only thing I can think of is the when
this DLL is loaded it pops up a message box. Could that be the
problem?

A buffer overflow?

This is the first time I read that error.

Of course, there is always the possibility that the dll is corrupted and not
working fine :)
Feb 4 '07 #3
"mjohnson" <cr****@hotmail.comwrote in message
news:11*********************@v45g2000cwv.googlegro ups.com...
>I bought a USB IR reciever and installed the driver. The developer
kit gives a DLL with the following information:
C++ Builder / Microsoft Visual C++:

#ifdef __cplusplus
extern "C" {
#endif

int __stdcall DoGetInfraCode(uchar * code, int extra, int *
codeLen);

#ifdef __cplusplus
}
#endif

So in my C# project I have done this:

public class IgorUSB
{
[DllImport("IgorUSB.dll")]
public static extern int DoGetInfraCode(ref byte[] code, int
extra, ref int codeLen);
}
Which I assume it the correct way to define the wrapper to the dll.

Next I added this to my Windows Form:

private void Form1_Load(object sender, EventArgs e)
{
byte[] code = new byte[12];
int extra = 0;
int len = 0;
IgorUSB.DoGetInfraCode(ref code, extra, ref len);
}

But I get the following error when I run it:

"LoaderLock was detected
Message: Attempting managed execution inside OS Loader lock. Do not
attempt to run managed code inside a DllMain or image initialization
function since doing so can cause the application to hang."

Does my code look correct? The only thing I can think of is the when
this DLL is loaded it pops up a message box. Could that be the
problem?

Your code is correct, the DLL's code is wrong.
The reason for the LoaderLock MDA is that the DLL class into another Win32 function that
requires an OS Loader lock.
Check this for more info:
http://msdn2.microsoft.com/en-us/library/ms172219.aspx

Willy.
Feb 4 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Gnanaprakash Rathinam | last post by:
Hi Expert, Is there a way to obtain assembly name in an unmanaged call? During Interop call between managed to unmanaged, I would like to know in unmanaged code about the caller of assembly file...
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
13
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make...
0
by: Ken Durden | last post by:
A little more info. I have a unmanaged C++ DLL, compiled without /CLR. Inside a Managed C++ DLL, I have the following class: MarshalWrapper.h ---- #ifdef _MANAGED __nogc #endif
11
by: Leon | last post by:
Are dataset automatically stored in memory? Does the dispose() method automatically dispose of the dataset in the code below? Do I have to dispose a dataset from memory or does the dataset...
3
by: Richard Lewis Haggard | last post by:
We are having a lot of trouble with problems relating to failures relating to 'The located assembly's manifest definition with name 'xxx' does not match the assembly reference" but none of us here...
22
by: SQACSharp | last post by:
I'm trying to get the control name of an editbox in another window. The following code set the value "MyPassword" in the password EditBox but it fail to return the control name of the EditBox. ...
3
by: Adam Clauss | last post by:
We have a Windows service written in C#. As of late, it has started crashing after running for as little as 2 minutes. I have a handler for AppDomain.UnhandledException which does NOT get called...
10
by: =?Utf-8?B?UmF2aSBTaGFua2Fy?= | last post by:
Hi, I have a requirement where I need to call methods written in VB.Net from a C++ code. I have been going crazy reading various articles on the net w.r.t interop and marshalling but an more...
8
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using vs2005, .net 2, C# for Windows application. I use DllImport so I can call up a function written in C++ as unmanaged code and compiled as a dll us vs2005. My application is able to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.