|
I tried both a timer and a file watcher before resorting to a thread.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
(The Timer's Elapsed method executes in its own thread.)
|
|
|
|
|
Hello,
VS 3.5
I have created a simple C++ DLL, and I want to use this in my C# program.
However, I am getting a Can't find PInvoke DLL 'TEST_SIP.dll
I have placed the DLL in my debug folder where my C# program is executed from. I am not sure if that is the correct place to put it.
Not sure where I am going wrong with this one.
many thanks for any suggestions,
Steve
Code in my C#
<br />
[DllImport("TEST_SIP.dll")]<br />
public static extern double Add(double a, double b);<br />
<br />
private void btnLogin_Click_1(object sender, EventArgs e)<br />
{<br />
string msg = SendData("Hello how are you");
MessageBox.Show(msg);<br />
}<br />
C++ header
<br />
#include <iostream><br />
<br />
namespace TEST_SIP<br />
{<br />
class TEST_SIP_Phone<br />
{<br />
public:<br />
static _declspec(dllexport) double Add(double a, double b);<br />
static _declspec(dllexport) double Subtract(double a, double b);<br />
static _declspec(dllexport) double Multiply(double a, double b);<br />
static _declspec(dllexport) double Divide(double a, double b);<br />
static _declspec(dllexport) std::string SendData(std::string data);<br />
};<br />
}
C++ Functions
<br />
#include "TEST_SIP.h"<br />
#include <stdexcept><br />
#include <cctype><br />
<br />
using namespace std;<br />
<br />
namespace TEST_SIP<br />
{<br />
double TEST_SIP_Phone::Add(double a, double b)<br />
{<br />
return a + b;<br />
}<br />
double TEST_SIP_Phone::Subtract(double a, double b)<br />
{<br />
return a - b;<br />
}<br />
double TEST_SIP_Phone::Multiply(double a, double b)<br />
{<br />
return a * b;<br />
}<br />
double TEST_SIP_Phone::Divide(double a, double b)<br />
{<br />
if(b == 0)<br />
{<br />
throw new invalid_argument("b cannot be zero!");<br />
}<br />
<br />
return a / b;<br />
}<br />
std::string TEST_SIP_Phone::SendData(std::string data)<br />
{<br />
return data; <br />
} <br />
}<br />
|
|
|
|
|
Try this: Simple Dll (Build this: cl /LD SimpleDll.cpp )
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
BOOL WINAPI DllMain(
HINSTANCE hinstDLL,
DWORD fdwReason,
LPVOID lpReserved )
{
switch( fdwReason )
{
case DLL_PROCESS_ATTACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
extern "C" __declspec(dllexport)
double Add(double a, double b)
{
return a + b;
}
extern "C" __declspec(dllexport)
double Subtract(double a, double b)
{
return a-b;
}
extern "C" __declspec(dllexport)
double Multiply(double a, double b)
{
return a*b;
}
extern "C" __declspec(dllexport)
double Divide(double a, double b)
{
if ( b != 0 )
return a/b;
return -999999999999999999999.0;
}
Hello world application (build: csc /t:exe HelloWorld.cs)
using System;
using System.Runtime.InteropServices;
namespace HelloWorld
{
class Hello
{
[DllImport("SimpleDll.dll", EntryPoint="Add", CallingConvention=CallingConvention.Cdecl)]
public static extern Double Add(Double a,Double b);
[DllImport("SimpleDll.dll", EntryPoint="Subtract", CallingConvention=CallingConvention.Cdecl)]
public static extern Double Subtract(Double a,Double b);
[DllImport("SimpleDll.dll", EntryPoint="Multiply", CallingConvention=CallingConvention.Cdecl)]
public static extern Double Multiply(Double a,Double b);
[DllImport("SimpleDll.dll", EntryPoint="Divide", CallingConvention=CallingConvention.Cdecl)]
public static extern Double Divide(Double a,Double b);
static void Main()
{
System.Console.WriteLine("Add: {0}", Add(3,4));
System.Console.WriteLine("Subtract: {0}", Subtract(7,4));
System.Console.WriteLine("Multiply: {0}", Multiply(3,4));
System.Console.WriteLine("Divide: {0}", Divide(12,4));
}
}
}
God bless,
Ernest Laurentin
modified on Thursday, March 6, 2008 1:09 PM
|
|
|
|
|
steve_rm wrote: [DllImport("TEST_SIP.dll")]
It may be looking only in the Windows directory for it.
Maybe you need to provide the full path?
|
|
|
|
|
Hi
I want to know :
in briefly, What's Mean this sentence : (C# is strongly typed language) ?
thanks
|
|
|
|
|
Gosh - that's such a hard one to find any answers on. If only there existed some repository of information that you could search. Click[^].
|
|
|
|
|
I've run out of sarcasm for such questions, you seemingly have a never-ending supply . What I need is a banging my head against a brick wall smiley
He who makes a beast out of himself gets rid of the pain of being a man
|
|
|
|
|
Phannon wrote: you seemingly have a never-ending supply
It's such a curse. The banging the head smiley is a good idea though.
|
|
|
|
|
Pete O'Hanlon wrote: It's such a curse
I have to say that since living in Glasgow I'm now generally more cynical and sarcastic that I ever was. I suppose working for a company for just under 2 years and with 3 name changes (and a fourth on the way) doesn't help.
|
|
|
|
|
Hmmm. Perhaps it was my time in Glasgow that turned me into the hollowed out bitter shell... Nope, I've always been sarcastic.
|
|
|
|
|
Phannon wrote: I've run out of sarcasm
You shouldn't, you should recycle rather than waste. Much nicer for the environment
(excluding the OP of course).
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
It means you have to type all of your own code manually.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
No, no, John, it means you must exhibit brute strength while pressing the keys on the keyboard as you type in your code.
|
|
|
|
|
Judah Himango wrote: it means you must exhibit brute strength while pressing the keys on the keyboard as you type in your code
Actually reminds me of when I learned to type. My dad had this big old mechanical typewriter that required a lot of effort (especially for a 7 year old) to push the keys. (I never got the hang of using my pinky though - I didn't have the strength and the bad habit of using my ring finger is still with me.)
|
|
|
|
|
I want show my image files when my OpenFileDialog Find File
in showing InisialDirectory...
OpenFileDialog sp = new OpenFileDialog();
sp.InisialDicrectory = dir;
list View mode or detail View mode
doesn't show image.
I need the small icon view mode.
I tried DirectoryInfo but got no solution.
It maybe a option for windows expolerer
or a option for a Directory?
I searched google but I didn't get it.
somewhere must be a solution for this.
help apprcieate.
thanks.
|
|
|
|
|
Hi,
I vaguely remember either a CodeProject article or a discussion thread on this very topic,
I guess dated early 2007.
Bottom line is there is no .NET support for this, if you really need it, you have to figure
out the window hierarchy of all the components in an OpenFileDialog, then send some messages
to the button window that controls the list view. Not really simple to do.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
hey guys, heres the deal. i got a few apps, running in production, but im constantly improving them. having to go from computer to computer and run the installer over and over (im using innosetup for the installer) i would like to incorporate some sort of auto update component. what would be the best approach towards this. should i keep the binaries on the svn server and somehow check against that and download the appropriate files and then somehow restart the app. or would it make more sense to somehow make the installer do the updating and just release 1 file? any input on the subject would be appreciated.
|
|
|
|
|
damianrda wrote: any input on the subject would be appreciated.
Any input? Really? What did you think of the input on the subject on the MSDN site[^]? Note that this information is so old it has been archived.
led mike
|
|
|
|
|
Yeah, you can do it manually like that; check some web server for updated version and pull those down as needed.
An alternative: .NET provides a built-in deployment mechanism called ClickOnce, which allows for automatic updates before starting your app, after running your app, or at any time via a single line of code. Read up on it here[^].
|
|
|
|
|
unfortunately, clickonce just isn't an option for me. i started to develop my own updater, however, im still puzzled about how it will update all the files (including the executable itself) when its still running, will i need to make this into a seperate application that replaces all the files and then starts up the main executable? also, id rather not have to keep two different sets of files, one on my developing machine and one on the server that the updates will be hosted at. i thought about maybe just downloading a setup file (which i already output for production) but im not sure if the installer (innosetup) will allow to "update/replace" files because as far as i know it just installs the app on a per version basis, so you can have your app version 1.1 and 1.2 installed at the same time. would it be feasible to somehow compress the update and have the program deflate the files?
|
|
|
|
|
I suppose the auto-update bit could be a different application, yeah. I've seen several applications like this.
Another possibility may be something like an application structure where your program is just a simple shell that never/rarely gets updated, and the rest of your application (the parts that get updated) are loaded like a plug-in, which can then be loaded/unloaded on demand through things like AppDomains.
|
|
|
|
|
hello
I'm looking how to start the default web browser with a given url from csharp
I can't believe how so "trivial" information is so hard to find
Thanks for any help
|
|
|
|
|
|
I found this !!
System.Diagnostics.Process.Start(@"myUrl");
|
|
|
|