小编kma*_*ks2的帖子

简单C执行HTTP POST并使用响应的示例

我想创建一个非常简单的C应用程序来执行HTTP发布.它将需要一些参数,并使用它们来构造URL.我只想做一个简单的HTTP POST并在不使用curl的情况下获得响应(这些库不会也不会安装在需要运行的机器上).

伪代码:

  1. 过程2 args

  2. 将args放入模板URL:http://api.somesite.com/apikey=ARG1&command=ARG2

  3. 在生成的URL上执行POST

  4. 消费回应

我的Google和SO搜索在此问题上没有任何结果.

c http http-post

71
推荐指数
4
解决办法
20万
查看次数

WPF窗口,透明背景包含不透明控件

我有一个窗口,外观如下:

在此输入图像描述

然而,我想要的是,主体中的Button控件(中间带有文字的灰色控件)的不透明度为1,完全不透明.当我继承这个项目时,不透明度在开始标记内的顶层设置为0.75 .现在据我了解,这将自动强制执行所有孩子,并说孩子不能覆盖.WindowGridWindow

那我怎么能完成透明背景但不透明的按钮呢?到目前为止我找到的唯一方法(作为WPF中的相对新手)是有两个单独的Windows,一个是透明背景,另一个没有背景但包含不透明控件.这非常hacky,如果可以,我想避免它.

我可以根据要求提供代码,但它实际上就像Window使用windowstyle = none和opacity .75 一样简单Grid,其中包含一些非常基本的Buttonetc控件.

有没有人建立过这样的Window,或者有其他人有洞察力生成一个?谢谢.

.net c# wpf user-interface transparency

49
推荐指数
1
解决办法
8万
查看次数

创建基本的C/C++ TCP套接字编写器

下面是我提出的以下基本套接字代码:

//General includes:
#include <iostream>
#include <stdio.h>
#include <string>

//Network related includes:
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>

//Target host details:
#define PORT 1234
#define HOST "74.74.74.74"

using namespace std;

//Function prototypes:
string MessageFormat(int, char**);
void MessageSend(string);

int main(int argc, char *argv[])
{
    //Parse arguments and format message:
    string message = MessageFormat(argc, argv);

    //Send the message out: 
    MessageSend(message);

    return 0;
}

string MessageFormat(int argc, char *argv[])
{
    //Massage the command line parameters
    // into my desired payload format.

    return message; …
Run Code Online (Sandbox Code Playgroud)

c c++ sockets tcp

16
推荐指数
2
解决办法
5万
查看次数

如何阻止异步tcp .NET代码耗尽整个系统的资源

在我的一些异步tcp服务器代码中,偶尔会发生错误,导致进程占用整个系统的内存.在查看日志,事件查看器和一些MS文档时,如果"调用应用程序多次向同一客户端调用异步IO,那么如果远程客户端停止其结束,则可能会看到堆碎片和私有字节增加"/O"导致内存使用量激增以及System.Threading.OverlappedData结构和字节数组的固定.

知识库文章提出的解决方案是"设置未完成缓冲区(发送或接收)与异步IO的上限."

怎么做到这一点?这是指发送到BeginRead的byte []吗?那么解决方案只是用信号量包装访问byte []?

编辑:信号量控制访问字节缓冲区或只是具有静态大小的字节缓冲池是两种常见的解决方案.我仍然存在的一个问题是,当这个异步客户端问题发生时(实际上它可能是一些奇怪的网络事件)有信号量或字节缓冲池将阻止我耗尽内存,但它无法解决问题.我的缓冲池可能会被问题客户端吞噬,实际上锁定了正确的函数合法客户端.

编辑2:遇到了这个伟大的答案.基本上它显示了如何手动取消固定对象.虽然异步TCP代码可以固定到幕后运行时规则,但有可能通过在使用前明确地固定每个缓冲区来覆盖它,然后在块的末尾或最后一个中取消固定.我现在想弄明白......

.net c# asynchronous tcp

8
推荐指数
1
解决办法
1309
查看次数

设置服务的运行凭据

我有一个服务,其中包含在安装期间使用的app.config文件.在ProjectInstaller类中,有代码来读取app.config文件,提取凭据并设置它们.目标是显示用户/密码提示.

在下面的示例中serviceUser,servicePassword它们只是对象范围的私有字符串.

以下块(驻留在ProjectInstaller ctor中)可以正常工作.也就是说,它设置服务的登录详细信息,从不提示用户:

public ProjectInstaller()
{
   InitializeComponent();
   LoadServiceSettings();

   //Install the service as a specific user:
   serviceProcessInstaller1.Account = ServiceAccount.User;
   serviceProcessInstaller1.Username = "MYDOMAIN\\myUser";
   serviceProcessInstaller1.Password = servicePassword; //pulled out of app.config by LoadServiceSettings call
}
Run Code Online (Sandbox Code Playgroud)

但是,以下不起作用:

public ProjectInstaller()
{
   InitializeComponent();
   LoadServiceSettings();

   //Install the service as a specific user:
   serviceProcessInstaller1.Account = ServiceAccount.User;
   serviceProcessInstaller1.Username = serviceUser; //both get pulled out of app.config by LoadServiceSettings() call;
   serviceProcessInstaller1.Password = servicePassword;

   WriteLog("The service user is *" + serviceUser + "*");
   // …
Run Code Online (Sandbox Code Playgroud)

.net c# windows service windows-services

7
推荐指数
0
解决办法
2540
查看次数

使用"<input type ="file".... />"而不是asp:FileUpload

我正在修改现有的ASP.NET项目.原作者错误地尝试通过将其可见性设置为隐藏并仅创建两个自定义样式的浏览和保存按钮来创建样式化的asp:FileUpload.

出于安全原因,IE不允许这样做.我的策略是尝试使用type ="file"的输入标签,就像这个例子一样.因此,如果我设置输入,<input type="file" ID="inputFile" /> 如何在我的代码中访问/保存文件,inputFile.SaveAs("someFile.txt");?另外(在后面的代码中)我可以做类似的事情inputFile.HasFile还是有其他类似的东西?

根据建议,我正在尝试以下内容:

             <td>
                Enabled: <asp:CheckBox ID="CheckBox2" runat="server" />    &nbsp;&nbsp;
                <div id="testFileUploader">>
                   <input type="file" id="browserHidden" runat="server" />
                   <div id="browserVisible"><input type="text" id="fileField" /></div>
                </div>
             </td>
Run Code Online (Sandbox Code Playgroud)

html c# asp.net file-upload

7
推荐指数
2
解决办法
4万
查看次数

ASP.NET应用程序代码中的相对路径

不熟悉ASP.NET我不确定我的问题的最佳解决方案.我有一行代码如:

xDoc.Load("Templates/template1.cfg");
Run Code Online (Sandbox Code Playgroud)

xDoc是一个XmlDocument.在我的项目中,在顶层有一个名为Templates的目录.当我在调试模式下运行项目时,我得到了一个DirectoryNotFoundException,显然它正在寻找模板目录C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\Templates.

如何在没有硬编码的情况下正确指向该目录?

.net c# asp.net

6
推荐指数
2
解决办法
2万
查看次数

Outlook 2007加载项:如何将图标添加到msoControlButton

背景:我正在使用C#在VS2010中开发Outlook 2007加载项.我正在做的具体事情是将菜单项添加到与电子邮件关联的上下文菜单中.我使用以下代码执行此操作:

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
   Application.ItemContextMenuDisplay += Application_ItemContextMenuDisplay;
}

private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}

private void Application_ItemContextMenuDisplay(Office.CommandBar commandBar, Outlook.Selection selection)
{
   var cmdButtonCallContact = (Office.CommandBarButton)commandBar.Controls.Add(Office.MsoControlType.msoControlButton, 1, System.Reflection.Missing.Value, 6, System.Reflection.Missing.Value);

   cmdButtonCallContact.Caption = "&Foo";
   //cmdButtonCallContact.Picture = ?
   cmdButtonCallContact.Click += cmdButtonCopy_Click;
}

private void cmdButtonCopy_Click(Office.CommandBarButton ctrl, ref bool canceldefault)
{
   System.Windows.Forms.MessageBox.Show("Bar");
}
Run Code Online (Sandbox Code Playgroud)

问题:似乎无法设置图片.Msdn示例依赖于我没有的AxHost转换函数.是否有一种简单的方法可以将图像或BitMap设置为图片?

谢谢.

.net c# office-addins outlook-addin

6
推荐指数
1
解决办法
4261
查看次数

记录对象的内存使用情况

可能有5或6个SO帖子切向触及这个,但没有一个真正回答这个问题.

我有一个Dictionary对象,我使用一种缓存来存储值.问题是我不知道它有多大 - 随着时间的推移它可能会变得越来越大,但我无法分辨,所以我无法衡量它的有效性,或者对用户如何使用该软件做出结论.因为这是一个将在很长一段时间内投入生产并监控某些东西的部分,所以连接内存分析器或任何类似的调试都没有意义.

理想情况下,我只需在我的Timer中调用一个类似于:

private void someTimer_Tick(object sender, EventArgs e)
{
   ...
   float mbMem = cacheMap.GetMemorySize();
   RecordInLog(DateTime.Now.ToString() + ": mbMem is using " + mbMem.ToString() + "MB of memory");
   ...
}
Run Code Online (Sandbox Code Playgroud)

这可以在不附加某些调试工具的情况下完成,以便可以使用部署方案吗?

.net c# memory

5
推荐指数
1
解决办法
268
查看次数

代码隐藏页面无法“看到”在 aspx 页面中声明的任何项目/控件

这是我的 Default.aspx 页面(删除了不必要的细节):

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div id="login">
    <!-- a bunch of markup has been removed, so this html will appear wrong and not valid, but it actually is -->
    <table align="center" width="80%" cellpadding="0" cellspacing="0" class="loginBg">
        <tr>
            <td colspan="2"><img src="images/Login_top.jpg" /></td>
        </tr>
        <asp:Panel runat="server" ID="pnlLoginIn">
        <tr>
            <td style="padding-left:20px;">Username</td>
            <td style="padding-right:15px;" align="right"><asp:TextBox id="txtUsername" runat="server" /></td>
            <asp:RequiredFieldValidator runat="server" ID="rfvUserName" ErrorMessage="*" ControlToValidate="txtUsername" ValidationGroup="credentials" Display="Dynamic" />
        </tr>
        <tr>
            <td style="padding-left:20px;">Password</td>
            <td style="padding-right:15px;" align="right"><asp:TextBox ID="txtPassword" TextMode="Password" runat="server" /></td>
                <asp:RequiredFieldValidator runat="server" ID="rfvPassword" ErrorMessage="*" ControlToValidate="txtPassword" ValidationGroup="credentials" …
Run Code Online (Sandbox Code Playgroud)

.net c# asp.net compiler-errors code-behind

5
推荐指数
1
解决办法
1万
查看次数