|
It's possible that the string being returned is not properly null-terminated.
Or it's possible that the C++ function is returning a locally declared variable, in which case it goes out of scope at the end of the C++ function.
Post the code of the C++ function.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Thanks Richard for your reply.
This is what I thought initially so I made sure that the local string will never go out of scope by declaring it as "static". According to C++ documentations the string::c_str() supposed to return a pointer to null terminated string:
http://www.cplusplus.com/reference/string/string/c_str/[^]
I agree with you, it sound like something happens to the buffer that it becomes no longer valid but I am not sure what happens exactly!.
|
|
|
|
|
Member 4211040 wrote: I agree with you, it sound like something happens to the buffer that it becomes no longer valid but I am not sure what happens exactly!.
Whatever the problem is, I'm sure it is more likely to be on the C++ side than the C# side.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Dear Expertise, I want to implement Voice Recognition in Our Traditional Product. we are using the technology is Visual Studio 2012 (v4.5) with C# web application and SQL server 2012.
Is it possible to impelement Voice Recognition in My Product?
I searched some link like our Code Project and Microsoft sites .. But Max of application using windows based application.
I want to implement using Voice Recognition to open our menu (pages) like Google Voice Recognition
If it is possible means, write suggessted Links for implement it..
Thanks in Advance
Palani Kumar.A
Sundaram Infotech Solutions
Chennai-14
Apkumaar
|
|
|
|
|
The big problem with speech APIs is that there is no one standard mechanism for it. Firefox has its own implementation[^] while Google has a different implementation[^].
|
|
|
|
|
|
This certainly won't work if you try to use it in a web app.
Clean-up crew needed, grammar spill... - Nagy Vilmos
|
|
|
|
|
Ya but it may give him the idea about the approach.. 
|
|
|
|
|
Clean-up crew needed, grammar spill... - Nagy Vilmos
|
|
|
|
|
[Removed - total nonsense.]
modified 7-Feb-14 6:03am.
|
|
|
|
|
That's a desktop technology, not a web based one. Speech recognition on the web is at a very early stage right now.
|
|
|
|
|
|
how ı write software ofusb dongle software for c# 
|
|
|
|
|
If you want to write a Driver for an USB dongle, bad news for you: This would probably be hard to achieve in C# because you'd need to write a driver.
Drivers are usually in a somewhat native code written:
Example 1[^]
Example 2[^]
Clean-up crew needed, grammar spill... - Nagy Vilmos
|
|
|
|
|
i have created a project, to track the daily task done. I used C# and SQL Database for this. (Client server model, more than 50 users are there.)
Now i want to implement a new functionality in my front end tool.
i want to view the data i have entred in the Database for a particular peroid of time. FromDate & ToDate.
i want to export the above from SQL Database to Excel.
I have used Excel Library to create a excel.
Query 1.
how an individual user can view the data he/ She entred in the Database for a particular peroid of time. FromDate & ToDate.
Query 2:
How to i export the above selected data to excel from SQL Database. (am placing a button in the fromend tool "Download")
|
|
|
|
|
1)
SELECT * FROM MyTable WHERE MyDateColumn BETWEEN '2014-01-01' AND '2014-01-31'
2)
Export DataTable to Excel with Formatting in C#[^]
[edit] forgot the FROM clause... Thanks Shameel - OriginalGriff[/edit]
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
modified 7-Feb-14 5:54am.
|
|
|
|
|
OriginalGriff wrote: SELECT * WHERE MyDateColumn BETWEEN '2014-01-01' AND '2014-01-31'
You're sure you aren't missing something?
|
|
|
|
|
Insufficient caffeine, I suspect...
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Happens all the time , have some ![Java | [Coffee]](https://codeproject.global.ssl.fastly.net/script/Forums/Images/coffee.gif)
|
|
|
|
|
Thanks for your reply.
In the above query, User will be giving the To Date and From Date during Runtime.
I will be including a caldender for that in my GUI.
So i think we need to fetch the user inputs(Both From & To Dates) in a variable. and use it in our query Statement.
Am confused how to do that. !
Your suggestions please.
|
|
|
|
|
Just pass the DateTime values as parameters to SQL. If you use DateTimePickers, there is no conversion needed:
using (SqlConnection con = new SqlConnection(strConnect))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("SELECT iD, description FROM myTable WHERE enterDate BETWEEN @FD AND @TD", con))
{
cmd.Parameters.AddWithValue("@FD", fromDatePicker.Value);
cmd.Parameters.AddWithValue("@TD", toDatePicker.Value);
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
int id = (int) reader["iD"];
string desc = (string) reader["description"];
Console.WriteLine("ID: {0}\n {1}", iD, desc);
}
}
}
}
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Great, Thank you.
Will implement it in my script.
Cheers,
|
|
|
|
|
You're welcome!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
 In a nut shell use a SP to perform this for you. Below is an example script that will create a table, Populate with so test data and a basic SP. Also note that SQL plays funny with the dates in regards WHERE and BETWEEN clauses.
Your BCP may be different from mine but it should be about that folder structure somewhere depending on the version of SQL that you have.
CREATE TABLE DBO.MyData
(
[ID] INT NOT NULL IDENTITY(1,1), --ALL TABLES SHOULD HAVE A ID EITHER SURRAGATE OR NATURAL.
[User] INT NOT NULL, --ASSUME FK CONSTRINT WITH YOU USER TABLE
[Data] VARCHAR(256) NULL,
[DateTimeStamp] DATETIME NOT NULL DEFAULT(GETDATE()), --TIME STAMP FOR THE ENTRY
)
GO
ALTER TABLE MyData ADD PRIMARY KEY (ID)
GO
INSERT INTO DBO.MyData([User], [Data]) VALUES (1,'MESSAGE 1 FROM USER 1')
INSERT INTO DBO.MyData([User], [Data]) VALUES (1,'MESSAGE 2 FROM USER 1')
INSERT INTO DBO.MyData([User], [Data]) VALUES (1,'MESSAGE 3 FROM USER 1')
INSERT INTO DBO.MyData([User], [Data]) VALUES (2,'MESSAGE 1 FROM USER 2')
INSERT INTO DBO.MyData([User], [Data]) VALUES (2,'MESSAGE 2 FROM USER 2')
INSERT INTO DBO.MyData([User], [Data]) VALUES (3,'MESSAGE 1 FROM USER 3')
INSERT INTO DBO.MyData([User], [Data]) VALUES (1,'MESSAGE 4 FROM USER 1')
GO
CREATE PROCEDURE GetData
(
@User INT = NULL,
@FROM DATETIME = NULL,
@TO DATETIME = NULL
)
AS
SELECT
D.[ID],
D.[DATA],
D.[DateTimeStamp]
FROM
DBO.MyData AS D
WHERE
D.[User] = ISNULL(@User, D.[User])
AND
D.[DateTimeStamp] >= ISNULL(@FROM, D.[User])
AND
D.[DateTimeStamp] <= ISNULL(@TO, D.[User])
ORDER BY D.[DateTimeStamp] DESC
GO
Below is an example C# application to consume this along with an example to use BCP for the Export that uses the same SP.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
int _user = 1;
DateTime _from = DateTime.Now.Add(new TimeSpan(-1, 0, 0, 0));
DateTime _to = DateTime.Now.Add(new TimeSpan(1, 0, 0, 0));
string dbServer = "localhost";
string dbDatabase = "";
string dbStoredProcedure = "[dbo].[GetData]";
string outPutFile = @"C:\Temp\MyData.txt";
string bcpPath = @"C:\Program Files\Microsoft SQL Server\110\Tools\Binn\";
using (var conn = new SqlConnection(
string.Format("Server={0};Database={1};Trusted_Connection=True;",
dbServer,
dbDatabase))
)
{
using (var command = conn.CreateCommand())
{
command.CommandText = dbStoredProcedure;
command.CommandType = System.Data.CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("User", _user));
command.Parameters.Add(new SqlParameter("From", _from));
command.Parameters.Add(new SqlParameter("To", _to));
conn.Open();
using (var r = command.ExecuteReader())
{
while (r.Read())
{
Console.WriteLine(r[0].ToString());
Console.WriteLine(r[1].ToString());
Console.WriteLine(r[2].ToString());
}
}
conn.Close();
}
}
string bcpArgs = string.Format("[{0}].{1} {2}, '{3}','{4}'",
dbDatabase,
dbStoredProcedure,
_user.ToString(),
_from.ToString("yyyy-MM-dd"),
_to.ToString("yyyy-MM-dd"));
System.Diagnostics.Process.Start(
string.Format("\"{0}BCP.exe\"",
bcpPath),
string.Format("\"{0}\" queryout {1} -c -t, -T -S {2}",
bcpArgs,
outPutFile,
dbServer));
System.Diagnostics.Process.Start(
"Notepad.exe", outPutFile);
}
}
}
The are always better way to do this but I hope that this gives a few pointers. to get better separation of concerns.
PS. You should try to avoid SELECT * as there is a over head and it leave the code open problems in then future.
BCP Ref:
BCP
http://technet.microsoft.com/en-us/library/ms162802.aspx
http://technet.microsoft.com/en-us/library/ms191516.aspx
|
|
|
|
|
I am trying to write code in C# that get mailbox details from user via Power Shell command.
The power shell command script is:
Import-PSSession -session (New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http:
Get-Mailbox -Identity helpdesk
The script runs OK from PowerShell.
Now my goal is to run it using C#.
This is my function:
private void button1_Click(object sender, EventArgs e)
{
m_RunSpace = RunspaceFactory.CreateRunspace();
m_RunSpace.Open();
Pipeline pipeLine = m_RunSpace.CreatePipeline();
Command newSession = new Command("New-PSSession");
newSession.Parameters.Add("-ConfigurationName", "Microsoft.Exchange");
newSession.Parameters.Add("-ConnectionUri", "http://myServer.myDomain.com/Powershell");
Command createSessionForExch = new Command("Import-PSSession");
createSessionForExch.Parameters.Add("-Session", newSession);
Command getMailbox = new Command("Get-Mailbox");
getMailbox.Parameters.Add("-Identity", "helpdesk");
pipeLine.Commands.Add(createSessionForExch);
pipeLine.Commands.Add(getMailbox);
Collection<PSObject> commandResults = pipeLine.Invoke();
foreach (PSObject cmdlet in commandResults)
{
}
}
But I receive an error that the "Get-Mailbox" command is not recognize:
http://imageshack.com/a/img593/664/x52q.png
Probably because the Import-PSSessions wasn't invok correctly.
I need help how to run the command Import-PSSession correctly from C#
|
|
|
|
|