|
I want to use VC++ *.lib into C# application. I know that I must compile the lib in to a dll. How can i do that? Any method and hits to me.
|
|
|
|
|
One way is to create a new .NET project called Class Library and copy over your VC++ code. Sometimes the "It Just Works" effect will be able to translate the code. Then when you compile it, you will have your dll which you can make other projects reference. The easier way would be to open the .lib project in VC++ 6.0 and go into Project->Settings and change the output from a static library (.lib) to a dynamic library (.dll). Compile it in VC++ 6.0 to get your .dll file, which your .NET project will be able to reference.
|
|
|
|
|
As the other reply says, I would link your static library (.LIB) into a regular DLL using Visual C++ 6.0. Then I would use P/Invoke to call into the unmanaged DLL from .NET.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
|
|
|
|
|
I'm trying to serialize a tree-like structure, and I get a System.InvalidOperationException: "When serializing an object of type RTBranch, a circular reference was found".
I've trached this to a public property which I don't want to be serialzed anyway, but the compiler says I can't apply the [NonSerializable] attribute to this. Removing the property fixes the problem (but obviously that's not what I want )
So far, the data only has a single branch (the root), but RTBranch has a public property AllBranches { get }which (recursively) returns all branches (i.e. this and all child branches, child child branches) in an ArrayList.
Pandoras Gift #44: Hope. The one that keeps you on suffering. aber.. "Wie gesagt, der Scheiss is' Therapie" boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
You can use the [XMLIgnore] (MSDN[^]) attribute on the offending property to stop it being serialized
"I think I speak on behalf of everyone here when I say huh?" - Buffy
-- modified at 3:36 Sunday 4th September, 2005
|
|
|
|
|
Thanks!
Would that work for non-XML serialization too?
Pandoras Gift #44: Hope. The one that keeps you on suffering. aber.. "Wie gesagt, der Scheiss is' Therapie" boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
No, I believe XMLIgnore attribute works only for XML serialization. I belive NonSerialized attribute is meant for binary serialization.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Cops & Robbers
Judah Himango
|
|
|
|
|
Hm... a little inconsistency.
Is is actually possible to tag only the attributes / properties I want to serialize?
Pandoras Gift #44: Hope. The one that keeps you on suffering. aber.. "Wie gesagt, der Scheiss is' Therapie" boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
Actually, I may have misled you in my previous post. The Serializable and NonSerializable attributes apply to wide-scale serialization: for example, if you wanted to use .NET remoting to send an object over to another process or another machine, these attributes would apply.
The XmlIgnore and XmlInclude attributes really apply only to the specialized case of XML serialization.
However, I use Xml serialization so rarely, you might be better off getting an answer from someone more experienced with it. At work, we almost exclusively do binary serialization, as it's quite a bit faster. The only xml serializing we do is with application config files, and even then, there's built-in support in the framework for configuration files.
peterchen wrote:
Is is actually possible to tag only the attributes / properties I want to serialize?
Sure. Mark your class as Serializable, then have it implement ISerializable. This will allow you to control precisely what data is saved and what is ignored.
*edit* Or, optionally, just mark your class as Serializable, then mark each field you don't want serialized as NonSerializable.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Cops & Robbers
Judah Himango
-- modified at 21:02 Sunday 4th September, 2005
|
|
|
|
|
When I execture my app "normally", I get a complete exception description. However, when I run it under the debugger, I only get a general text in the "Output" Window.
Any way to have full exception reporting in debug mode?
Pandoras Gift #44: Hope. The one that keeps you on suffering. aber.. "Wie gesagt, der Scheiss is' Therapie" boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
(1) How to make a button the default one?
(2) How to rearrange the control order (except juggling the TabOrder property on each control individually, trying not to hit one that was already used)
Pandoras Gift #44: Hope. The one that keeps you on suffering. aber.. "Wie gesagt, der Scheiss is' Therapie" boost your code || Fold With Us! || sighist | doxygen
-- modified at 3:00 Sunday 4th September, 2005
|
|
|
|
|
How to make a button the default one?
Use the Form's AcceptButton property (under Misc)
How to rearrange the control order
I'd like to know too - I only ever found it once and that was by accident
"I think I speak on behalf of everyone here when I say huh?" - Buffy
|
|
|
|
|
|
Sweet
"I think I speak on behalf of everyone here when I say huh?" - Buffy
|
|
|
|
|
Hi all,
Can anyone please explain how to add a binary file resource such as a wav, zip, avi, etc... to a .resources file BY CODE?
I've been searching msdn site for an answer but all the examples apply to Visual Studio .NET resource editors, as all programmers own and use it, right? And correct me if i'm wrong, Microsoft says that files can only be embeded directly to the assembly and not to .resources files.
I use notepad to write software and compile with batch files, so never think about suggesting me on using Visual Studio .NET resource editors.
Thanx man,
Heinz
|
|
|
|
|
I would look closely at the System.Resources.ResourceWriter class; I think it does everything you're looking for.
I actually used it one time when I wanted to embed some sound in a Windows app.
Something like the following would probably do the trick if you're just wanting to write binary resources to the file:
using System;
using System.IO;
using System.Resources;
using System.Runtime.Serialization.Formatters.Binary;
class ResourceUtility
{
public static void WriteResourceToFile(string name, object graph, string fileName)
{
BinaryFormatter serializer = new BinaryFormatter();
MemoryStream mem = new MemoryStream();
serializer.Serialize(mem, graph);
using (ResourceWriter writer = new ResourceWriter(fileName))
{
writer.AddResource(name, mem.GetBuffer());
writer.Generate();
writer.Close();
}
}
}
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Hi,
Thanx for your method. I use ResourceWriter in my programs to create resources and your method use it too so it's easy to understand how it works.
BUT, how do i call this function, i mean: If i want to add a .wav, a .zip or a .txt file, which parameter should i pass to the graph object?
For example: If i want to add an image i send the parameter 'Image.FromFile("C:\MyImage.jpg");' to the graph object.
If a want to add and icon i send the parameter 'new Icon(C:\MyIcon.ico);'
Thanx in advance.
|
|
|
|
|
If you have a file whose contents you want to add to a .resources file, use a FileStream to read the contents of the file, and the buffer from that stream as the source of the resource you're adding.
My example was just a generic example assuming you wanted to add a managed object as a resource.
Hope this helps.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Hi, thanx for your reply. I just want to add a .zip file for example, if i add this zip to a .resources with a visual editor like "Resourcer" or the sharpdevelop editor, you can see the object type, when i add the zip the type shown is System.Byte[] and this type is shown for all the binary files cause managed object shows as System.Drawing.Icon System.Drawing.Image System.String
I just want to add by code a non managed file so the type shows as System.Byte[]
I've tried all but never found how.
Thanx in advance
|
|
|
|
|
As I mentioned in my previous message, if you have a file you want to embed in a resource file, create a file stream using the target file, read the stream from start to end (will yield a byte array - type = byte[]), then use that byte array as the source of the resource entry. When you read the bytes back out of the resource, you can then use whatever kind of writer you want to "rehydrate" the bytes into a file, an image etc.
Here is an example of embedding a single .JPG image in a resource file - it's a trivial example, but it works and should get you started in the right direction:
public static void WriteResourceToFile(string importPath, string resourceKey, string resourceFileName)
{
byte[] buffer = null;
using (Stream file = new FileStream(importPath, FileMode.Open, FileAccess.Read))
{
buffer = new byte[file.Length];
file.Read(buffer, 0, (int)file.Length);
file.Close();
}
using (ResourceWriter writer = new ResourceWriter(resourceFileName))
{
writer.AddResource(resourceKey, buffer);
writer.Generate();
writer.Close();
}
}
The preceding function could be called to store an image file using:
ResourceUtility.WriteResourceToFile(@"c:\pic1.jpg", "pic1", "image.resources");
To read the image back out of the resource file, you could implement something like:
private System.Drawing.Image ReadImageResourceFromFile(string resourceFileName, object resourceKey)
{
MemoryStream stream = null;
Image i = null;
using (ResourceReader reader = new ResourceReader(resourceFileName))
{
IDictionaryEnumerator loop = reader.GetEnumerator();
while (loop.MoveNext())
{
if (loop.Key == resourceKey)
{
byte[] buffer = (byte[])loop.Value;
stream = new MemoryStream(buffer);
break;
}
}
reader.Close();
}
if (stream != null && stream.Length > 0)
{
stream.Position = 0;
i = Image.FromStream(stream);
stream.Close();
}
return i;
}
...and could be called using:
System.Drawing.Image result = ReadImageResourceFromFile("image.resources", "pic1");
Hope this helps.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Thanx man, it worked for me, thanx again for your help.
|
|
|
|
|
Respected Sir
Sir i am suffering from one problem and that is i
want to use a function s of a dll file in my c shap project this file is made up in vc++ .in .net frame work when i add a reference it donot allow to add the reference of this file kindly guide me in this regard.
Good Bye
Sajjad
From Sayed Sajjad Raza Zaidi
Itszaidi@hotmail.com
itssajjadraza@yahoo.com
|
|
|
|
|
P/Invoke allow you To use use unmanaged dll functions in your C# application P/Invoke was originally intended to provide access to the Windows API but you can use it to call function from any dll you need to use DLLImport attribute
and declare the method as a static extern
For example If you want to use FindWindow Function from user32.dll you will write somthing like
[DllImport("user32.dll", SetLastError = true)]<br />
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
Look at this article for more info
Calling Win32 DLLs in C# with P/Invoke[^]
MCAD
-- modified at 16:15 Sunday 4th September, 2005
|
|
|
|
|
hey all
i have a string '<cc1:CustomControl id="test" att1="some crap" att2="123"></cc1:CustomControl>'
this is valid xml so is it possible to put this into a node and get a collection of attributes?
|
|
|
|
|
Yes.
Just create an XmlDocument object and load the string into it with the LoadXml method. The node will be the root element, so you can get it using the DocumentElement property.
---
b { font-weight: normal; }
|
|
|
|