|
Hello,
I would like to wrap a text file into my project, and copy it out to a directory when a button is clicked. My current project is a dll plugin. Is there a way to have a folder inside of the solution explorer to hold these files, and then to be able to copy them out of this folder (which lives inside of the dll) to a directory?
If this is not possible, what is the most efficient way to write a text file, where carriage returns and spacing are crucial? It's a couple of hundred lines, so it'd be pretty tedious to write a string like the following which I was hoping to avoid and only use the below as a last resort.
string fileContentsLineByLine= "test" + System.Environment.NewLine +
"test2" + System.Environment.NewLine +
"test3";
Thank you for reading.
|
|
|
|
|
You can add the file to your project's resources and access it from there at run time.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Thanks for the reply!
How can I reference it in the resources directory or is there a term for this I can google to see examples?
|
|
|
|
|
Take a look at this MSDN article[^] for full details.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Thank you Richard! That article was very informative, although I have one more question.
I was able to get this to work with a bmp file, but I cannot seem to get it to work with a text file, or exe or dll?
With the bmp file, I can use the following code
System.Drawing.Bitmap bitmap1 = Project.Properties.Resources.bmppicture;
bitmap1.Save(theDirectory + @"\" + @"Fdr\bitmap1.bmp");
Scratch that, File.WriteAllBytes() works for txt files
Is there a way to Dllimport from an embeded dll that is inside of the resources folder?
modified 12-Jan-12 15:03pm.
|
|
|
|
|
turbosupramk3 wrote: Is there a way to Dllimport from an embeded dll that is inside of the resources
folder?
Question isn't clear.
Given that you have a dll named X.
And you want to embed X into your application as a resource?
If the answer to that is yes then why would you want to do that?
|
|
|
|
|
Hi,
I'd like to not only embed it as a resource, but load it into memory from the embedded location so that I don't have to copy it anywhere when I import it. This particular dll is unmanaged Delphi code, in case that matters.
|
|
|
|
|
turbosupramk3 wrote: I'd like to not only embed it as a resource, but load it into memory from the embedded location so that I don't have to copy it anywhere when I import it. This particular dll is unmanaged Delphi code, in case that matters.
I doubt there is an reasonable reason for doing that. Some possible reasons.
- To 'protect' it.
- Unable to figure out how to access it.
- It won't run with the normal load
None of those are valid.
But regardless achieving it is going to be difficult. It is going to require a lot of code and lot of expertise and even an expert in several languages is going to have a difficult time getting it correct (bugs that do not cause failures.)
Some links that follow. (Keep in mind licensing concerns when looking at the code.)
http://delphi.about.com/od/windowsshellapi/a/delphi-load-resource-dll-into-memory.htm[^]
http://www.joachim-bauch.de/tutorials/loading-a-dll-from-memory/[^]
|
|
|
|
|
You are right, this is more advanced then my skills ... thank you for the information.
|
|
|
|
|
turbosupramk3 wrote: Is there a way to Dllimport from an embeded dll that is inside of the resources folder?
I have never heard of that. As far as I know the DllImport will expect to load a DLL from one of the library directories, so I don't know of any way it could be redirected to the resources. Also why would you wish to do such a thing, it seems over complicated.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
You can extract any embedded resource (something compiled in with /res: in the compiler command line or with a build action selected as Embedded Resource in an IDE) with something along the lines of
Assembly.GetExecutingAssembly().GetResourceManifestStream(filename);
If you're using Visual Studio it has a horrible habit of prepending the default namespace on the front of all your resource files, so either (i) don't use VS or (ii) adjust all your resource-grabbing calls accordingly.
turbosupramk3 wrote: Is there a way to Dllimport from an embeded dll that is inside of the resources folder?
No. DllImport attributes are compile-time-bound to a file (though I'm not sure if the file actually has to exist at the appropriate time). You can load a managed DLL from resources using the byte[] overload of Assembly.Load, but to access an unmanaged one at runtime is something I don't know how to do. I would set the working directory of the application to a folder you have write access to and then copy the DLL you are trying to use in there when you run (or just include it in the deployment package).
|
|
|
|
|
For completeness I am re-posting the following link up here.
It explains how one can load an unmanaged dll using a source besides a file. Note that this technique requires a high level of experience both in C/C++, windows architecture and file formats. And it is also likely that it could require changes based on things like OS version and probably for 64 bit formats.
http://www.joachim-bauch.de/tutorials/loading-a-dll-from-memory/[^]
But it is possible.
|
|
|
|
|
Is there a support for serial ports in WinRT metro style application in the Developpers preview or is there going to be in the release version.
I need to communicate with our company proprietary device. In Windows CE I did it with Windows.IO.Ports.SerialPort and used FTDI USB to serial driver and dongle.
|
|
|
|
|
Hi everyone,
im working on a project to detect car license plate using ABBYY FineReader Engine 10 SDK. And i would like to ask, how do i do closing on car license plate? Because i want to remove the protruding words and numbers from the car plates such that the image is 2D.
P.S, your answer is greatly appreciated And i do hope to get some sample codes as reference. Modifications will be done to given sample codes.
Thank you!!
|
|
|
|
|
I hate to tell you, but no one is going to give you the source code. You're going to have to figure this one out yourself.
|
|
|
|
|
Sadly, I have to create a COM object in C# that will be consumed by a PowerBuilder 11.5 application. Given some parameters, I need to return a byte array. I'm having trouble determining how to do this. I've tried including a ref parameter of type byte[]; no dice. I've tried declaring the parameter as "out"; again, no dice. I know the bytes I want to return are valid because I wrote them out to a file to verify. Can someone please tell me the best method to return a byte array to a calling application?
|
|
|
|
|
As I am new at this, and this is my first attempt at actually writing code, some of you may chuckle (or laugh out loud at the simplistic code)... please be merciful.
I keep getting the error message: A namespace cannot directly contain members such as fields or methods"
I have visited MSDN, and virtually every google and bing hit out there, but no matter how I change the first entry, I get the same message. Could someone help?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _11012_debproject_2
{
class Program
{
static void Main(string[] args);
int number1;
int number2;
int Multiply;
}
Console.WriteLine( "Enter first number:" )
number1 (Console.Readline());
Console.WriteLine( "Enter second number:")
number2 ( Console.ReadLine());
product = number1 * number2;
Console.WriteLine( "product is {0}",product );
}
|
|
|
|
|
Check your curly braces... they don't properly enclose the object.
Will Rogers never met me.
|
|
|
|
|
Roger:
Thank you. I appreciate your help.
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _11012_debproject_2
{
class Program
{
static void Main(string[] args);
{
int number1;
int number2;
int Multiply;
Console.WriteLine( "Enter first number:" );
number1=Convert.ToInt32(Console.Readline());
Console.WriteLine( "Enter second number:");
number2=Convert.ToIn32( Console.ReadLine());
Multiply= number1 * number2;
Console.WriteLine( "Multiply is {0} ",Multiply);
}
}
}
|
|
|
|
|
Thank you for your help. I appreciate your time.
|
|
|
|
|
I wanted to wander back and thank you formally. I changed "product" to "muliply" and it looks like I neglected the "convert to 32" as well as my other errors.
Thank you again.
modified 12-Jan-12 12:05pm.
|
|
|
|
|
As mentioned, your } brackets are wrong and the problems starts with the ; at the end of your Main method.
namespace _11012_debproject_2
{
class Program
{
static void Main(string[] args)
{
int number1;
int number2;
int multiply;
Console.WriteLine( "Enter first number:" );
number1 (Console.Readline());
Console.WriteLine( "Enter second number:")
number2 ( Console.ReadLine());
product = number1 * number2;
Console.WriteLine( "product is {0}",product );
}
}
}
You would do well to read a bit about naming conventions. namespaces should start with a letter. Not a number of underscore.
Enjoy
"You get that on the big jobs."
|
|
|
|
|
I am having difficulty posting replies.
If this is a double, I apologize. Thank you for your assistance. My namespace "name" is a bad habit I must break (from business emails with the date at the beginning of the Subject line). Thank you for the reminder.
Also, the braces? I have no excuse for the carelessness.
|
|
|
|
|
Deborah Palmer McCain wrote: I am having difficulty posting replies.
Don't worry about that, Deborah. Quite a few of us have been having trouble with that for the past week or so. The site administrators are running some SQL Server scripts that are processor-intensive, and that tends to bog things down a bit. Be patient... It will get better.
Will Rogers never met me.
|
|
|
|