I'm attempting to implement a 3rd party COM library in a C# application,
and have run up against the following problem in my development. I am
trying to use a particular method call of an object, but it looks like
tlbimp has imported the call in a way that I can't figure out how to get
my data in.
SDK:
VARIANT_BOOL ReadMemory(unsi gned char* Data, long DataSize);
IL file:
.method public hidebysig newslot virtual instance bool
ReadMemory([in] unsigned int8& Data,
[in] int32 DataSize) runtime managed internalcall
{
.override [Class]::ReadMemory
} // end of method [Class]::ReadMemory
The Data parameter is supposed to be the contents of an image file (JPG,
etc) read into memory, and in my application is declared as byte[]. The
IL call has it as a pointer to a byte. How can I change the IL file to
the correct type so that I can send in a byte[]?
Thanks!
Gabe
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it! 7 1497
Gabe,
I'm a little confused by the original signature, since you have a
VARIANT_BOOL that is returned, but then you have an unsigned char pointer,
which is not automation compliant. If it was automation compliant, then I
would expect a safearray, and if it was not, I'd expect the return type to
be BOOL. If it was declared as a SafeArray, then the interop library
generated would have exposed a byte array.
If you can't change that, then what you will want to do is define your
interface in code, or modify the IL output by the TLBIMP tool (using ILDASM
to get the IL from the assembly, editing it, and then calling ILASM to
recompile it). When you re-define the COM interface, you will want to
expose the unsigned char as an IntPtr. This will cause the pointer to be
passed to your code.
Then, you will have to convert the array to a byte array and copy it
into managed memory. You can do this using the various static methods on
the Marshal class. If you need help with this, I can elaborate.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Gabe Covert" <no****@thecove rts.net> wrote in message
news:u%******** ********@TK2MSF TNGP11.phx.gbl. ..
I'm attempting to implement a 3rd party COM library in a C# application, and have run up against the following problem in my development. I am trying to use a particular method call of an object, but it looks like tlbimp has imported the call in a way that I can't figure out how to get my data in.
SDK: VARIANT_BOOL ReadMemory(unsi gned char* Data, long DataSize);
IL file: method public hidebysig newslot virtual instance bool ReadMemory([in] unsigned int8& Data, [in] int32 DataSize) runtime managed internalcall { .override [Class]::ReadMemory } // end of method [Class]::ReadMemory
The Data parameter is supposed to be the contents of an image file (JPG, etc) read into memory, and in my application is declared as byte[]. The IL call has it as a pointer to a byte. How can I change the IL file to the correct type so that I can send in a byte[]?
Thanks!
Gabe
*** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
Unfortunately, I can't change it, as it's a third-party COM library...
I've dug into the IL, but being a fairly new C# developer, and with my
C++ skill sbeing fairly rusty, I'm perplexed as to what changes I would
need to make to the IL to get the parameter conversion done correctly.
Any help you can offer would be greatly appreciated!
Gabe If you can't change that, then what you will want to do is define your interface in code, or modify the IL output by the TLBIMP tool (using
ILDASM to get the IL from the assembly, editing it, and then calling ILASM to recompile it). When you re-define the COM interface, you will want to expose the unsigned char as an IntPtr. This will cause the pointer to
be passed to your code.
Then, you will have to convert the array to a byte array and copy it into managed memory. You can do this using the various static methods
on the Marshal class. If you need help with this, I can elaborate.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Gabe,
Can you post the IDL that is used for the particular interface (you can
use OLE view to generate it). With that, I can give you a piece of code
used to represent the interface which you can cast to and use.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Gabe Covert" <no****@thecove rts.net> wrote in message
news:eZ******** ******@tk2msftn gp13.phx.gbl... Unfortunately, I can't change it, as it's a third-party COM library... I've dug into the IL, but being a fairly new C# developer, and with my C++ skill sbeing fairly rusty, I'm perplexed as to what changes I would need to make to the IL to get the parameter conversion done correctly.
Any help you can offer would be greatly appreciated!
Gabe
If you can't change that, then what you will want to do is define your interface in code, or modify the IL output by the TLBIMP tool (using ILDASM to get the IL from the assembly, editing it, and then calling ILASM to recompile it). When you re-define the COM interface, you will want to expose the unsigned char as an IntPtr. This will cause the pointer to be passed to your code.
Then, you will have to convert the array to a byte array and copy it into managed memory. You can do this using the various static methods on the Marshal class. If you need help with this, I can elaborate.
*** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
Here is what I find in OLE view:
[helpstring("Rea ds JPG, BMP, GIF, and TIFF file formats from memory")]
HRESULT _stdcall ReadMemory(
[in] unsigned char* Data,
[in] long DataSize,
[out, retval] VARIANT_BOOL* Success);
If I use the ildasm, I get the following:
.method public hidebysig newslot virtual
instance bool ReadMemory([in] unsigned IntPtr Data,
[in] int32 DataSize) runtime
managed internalcall
{
.override Identix.FaceIt. Media.IDibImage ::ReadMemory
} // end of method DibImageClass:: ReadMemory
Thanks!
Gabe
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Gabe,
You would need to define the interface in C# like this:
[Guid("get guid from OLEVIEW")]
// I'm assuming that the interface derives from IUnknown in COM, in which
case, this attribute is needed.
[InterfaceType(C omInterfaceType .InterfaceIsIUn known)]
public interface ISomeInterface
{
[retval:MarshalA s(UnmanagedType .VariantBool)]
bool Readmemory(IntP tr Data, int DataSize);
}
Then, when you implement it, you can use the methods on the Marshal
class to convert from the pointer (in Data) to the byte array you need.
If you don't want to marshal the data, you can use unsafe code and take
a pointer to void, and then just access the memory directly (however, you
need the specific permission for unsafe code). This might be a better
solution, since it you won't have to copy the memory from unmanaged to
managed.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Gabe Covert" <no****@thecove rts.net> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. .. Here is what I find in OLE view:
[helpstring("Rea ds JPG, BMP, GIF, and TIFF file formats from memory")] HRESULT _stdcall ReadMemory( [in] unsigned char* Data, [in] long DataSize, [out, retval] VARIANT_BOOL* Success);
If I use the ildasm, I get the following: method public hidebysig newslot virtual instance bool ReadMemory([in] unsigned IntPtr Data, [in] int32 DataSize) runtime managed internalcall { .override Identix.FaceIt. Media.IDibImage ::ReadMemory } // end of method DibImageClass:: ReadMemory
Thanks!
Gabe
*** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
Where would I declare this? In my code? I attempted to add a new class
library to my solution, and implement the following, but I get errors
when compiling saying that Guid and InterfaceType could not be found,
and I can't seem to find a namespace to add to the using section...
[Guid("7CA67280-8914-11D2-B814-00104BC60522")]
[InterfaceType(C omInterfaceType .InterfaceIsIUn known)]
public interface IDibImageInterf ace
{
[retval:MarshalA s(UnmanagedType .VariantBool)]
bool ReadMemory(IntP tr Data, int DataSize);
}
Did I do something wrong in the declaration, or where the declaration
goes?
Gabe
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Gabe,
Those classes are in the System.Runtime. InteropServices namespace.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Gabe Covert" <no****@thecove rts.net> wrote in message
news:eN******** ******@TK2MSFTN GP11.phx.gbl... Where would I declare this? In my code? I attempted to add a new class library to my solution, and implement the following, but I get errors when compiling saying that Guid and InterfaceType could not be found, and I can't seem to find a namespace to add to the using section...
[Guid("7CA67280-8914-11D2-B814-00104BC60522")] [InterfaceType(C omInterfaceType .InterfaceIsIUn known)] public interface IDibImageInterf ace { [retval:MarshalA s(UnmanagedType .VariantBool)] bool ReadMemory(IntP tr Data, int DataSize); }
Did I do something wrong in the declaration, or where the declaration goes?
Gabe
*** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: R.Wieser |
last post by:
Hello All,
I'm trying to get a "Virtual Listbox" to work. I've currently got a form,
and used CreateWindowExA to create a ListBox with the LBS_OWNERDRAWFIXED and
LBS_NODATA flags on it. I've allso subclassed the window and do see all
kinds of WS_??? messages coming by.
But now I'm stuck :-\
I've got *no* idea what to do next, and all my searching on the web leads me
|
by: Joh |
last post by:
hello,
i'm trying to understand how i could build following consecutive sets
from a root one using generator :
l =
would like to produce :
, , , ,
|
by: Roy Smith |
last post by:
I understand that "delete xp" deletes a scalar object and "delete xp"
deletes an array of objects, but what I don't understand is why you need
to tell the compiler which you're doing.
When you do "delete xp", the delete procedure (not sure if that's the
right terminology) obviously knows how many objects were allocated by
the corresponding "new" call. So, why can't it just know whether you
did "new x" or "new x"?
|
by: Jack Addington |
last post by:
I've got a fairly simple application implementation that over time is going
to get a lot bigger. I'm really trying to implement it in a way that will
facilitate the growth. I am first writing a WinForms interface and then
need to port that to a web app. I am kinda stuck on a design issue and need
some suggestions / direction.
Basically I have a business layer that I want to use to process any
dataentry logic (row focus changes, data...
|
by: Sai Kit Tong |
last post by:
In the article, the description for
"Modiy DLL That Contains Consumers That Use Managed Code and DLL Exports
or
Managed Entry Points"
suggests the creation of the class ManagedWrapper.
If I need to build multiple mixed mode dll's used by a consumer application,
do I have to implement multiple ManagedWrapper's (each embedded in
indiviudal DLL project) and call all of them in my consumer application?
| |
by: Bill Borg |
last post by:
Hello,
I call a function recursively to find an item that exists *anywhere* down
the chain. Let's say I find it five layers deep. Now I've got what I need and
want to break out of that whole stack and continue execution at the point of
the initial call. Is that possible?
Thanks,
Bill
|
by: sommarlov |
last post by:
Hi everyone
>From one of our systems an xml file is produced. I need to validate
this file before we send it to an external system for a very lenghty
process. I cannot change the xml file layout.
The solution i got today is very slow, and i need help to find another
solution.
Here is the xml file. It consists of a list of position ids (ESTOXX50
INDEX_BM_E and FTSE INDEX_BM_E), and below that a list of tags for each
position id. What i...
|
by: bsruth |
last post by:
I tried for an hour to find some reference to concrete information on
why this particular inheritance implementation is a bad idea, but
couldn't. So I'm sorry if this has been answered before. Here's the
scenario:
We have a base class with all virtual functions. We'll call this the
Animal class. We then make two classes Fish and Bird that both inherit
from Animal. In the program, we have a single array of Animal pointers
that will...
|
by: sara |
last post by:
i am studying a computer engineering and i started taking programming
using C++ since month
i have question i think it`s easy for you all *prof.programmer* but
it`s bit diffecult for me plzz i need your help. (: this is the
question:
** A new telephone communication company needs a billing calculation
program. The cost of a call is based on the following three inputs that
should be entered by the user, and they are explained as follows.
|
by: Siyodia |
last post by:
This is a java program which i need to run facing compilation error
Its consuming a third party web service method
I have the supported files(folder) which contain necessary class files org/apache/axis
The following is what i need to do but am unable to do
////////////////////////////////////////////////////////////////////////////////////////////
set classpath where the below jars are located....
axis.jar
commons-discovery.jar
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |