【SQL Server CE2.0】打开加密的数据库(源代码)

  1 HRESULT  hr;
  2 DBID  TableName;  // name of table for new constraint
  3 DBID  ColumnList[1]; // name of column for new constraint
  4 DBID  ConstraintName; // name of new constraint
  5 DBPROP  dbprop[1];
  6 DBPROP  sscedbprop[2]; // Property array for SSCE security properties
  7 DBPROPSET dbpropset[2];
  8 DBCONSTRAINTDESC rgConstraintDescs[1]; // Structure for constraint properties
  9 IDBInitialize  *pIDBInitialize       = NULL;        
 10 IDBProperties  *pIDBProperties       = NULL;        
 11 IDBCreateSession *pIDBCreateSession    = NULL;
 12 ITableDefinitionWithConstraints *pITbleDefWithConstrt = NULL; // supports adding constraints
 13 int i = 0;
 14 // Create an instance of the OLE DB Provider
 15 hr = CoCreateInstance(CLSID_SQLSERVERCE_2_0, 0, CLSCTX_INPROC_SERVER,
 16  IID_IDBInitialize, (void**)&pIDBInitialize);
 17 if(FAILED(hr))
 18 {
 19  RETAILMSG(1,(TEXT("2==CoCreateInstance failed: 0x%x/r/n"),hr));
 20  goto CleanExit;
 21 }
 22 // Initialize a property with name of database
 23 // Open an exsiting database myDatabase
 24 VariantInit(&dbprop[0].vValue);
 25 for(i = 0;i < sizeof(sscedbprop) / sizeof(sscedbprop[0]);i++)
 26 {
 27  VariantInit(&sscedbprop[i].vValue);
 28 }
 29 dbprop[0].dwPropertyID = DBPROP_INIT_DATASOURCE;
 30 dbprop[0].dwOptions = DBPROPOPTIONS_REQUIRED;
 31 dbprop[0].vValue.vt = VT_BSTR;
 32 dbprop[0].vValue.bstrVal = SysAllocString(L"Encrypted.sdf");
 33 // Specify the property for encryption. 
 34 sscedbprop[0].dwPropertyID = DBPROP_SSCE_ENCRYPTDATABASE;
 35 sscedbprop[0].dwOptions = DBPROPOPTIONS_REQUIRED;
 36 sscedbprop[0].vValue.vt = VT_BOOL;
 37 sscedbprop[0].vValue.boolVal = VARIANT_TRUE;
 38 // Specify the password.
 39 sscedbprop[1].dwPropertyID = DBPROP_SSCE_DBPASSWORD;
 40 sscedbprop[1].dwOptions = DBPROPOPTIONS_REQUIRED;
 41 sscedbprop[1].vValue.vt = VT_BSTR;
 42 sscedbprop[1].vValue.bstrVal = SysAllocString(L"123456"); //密码
 43 if(NULL == sscedbprop[1].vValue.bstrVal)
 44 {
 45  hr = E_OUTOFMEMORY;
 46  goto CleanExit;
 47 }
 48 // Initialize the property set
 49 dbpropset[0].guidPropertySet = DBPROPSET_DBINIT;
 50 dbpropset[0].rgProperties = dbprop;
 51 dbpropset[0].cProperties = sizeof(dbprop)/sizeof(dbprop[0]);
 52 dbpropset[1].guidPropertySet = DBPROPSET_SSCE_DBINIT;
 53 dbpropset[1].rgProperties = sscedbprop;
 54 dbpropset[1].cProperties = sizeof(sscedbprop)/sizeof(sscedbprop[0]);
 55 //Set initialization properties.
 56 hr = pIDBInitialize->QueryInterface(IID_IDBProperties, (void **)&pIDBProperties);
 57 if(FAILED(hr))
 58 {
 59  RETAILMSG(1,(TEXT("2==pIDBInitialize->QueryInterface failed: 0x%x/r/n"),hr));
 60  goto CleanExit;
 61 }
 62 // Sets properties in the Data Source and initialization property groups
 63 hr = pIDBProperties->SetProperties(sizeof(sscedbprop) / sizeof(sscedbprop[0]), dbpropset); 
 64 if(FAILED(hr))
 65 {
 66  RETAILMSG(1,(TEXT("2==pIDBProperties->SetProperties failed: 0x%x/r/n"),hr));
 67  goto CleanExit;
 68 }
 69 // Initializes a data source object 
 70 hr = pIDBInitialize->Initialize();
 71 if(FAILED(hr))
 72 {
 73  RETAILMSG(1,(TEXT("2==pIDBInitialize->Initialize failed: 0x%x/r/n"),hr));
 74  goto CleanExit;
 75 }
 76 //只有已经创建表,以下操作才可能成功
 77 hr = pIDBInitialize->QueryInterface(IID_IDBCreateSession,(void**)&pIDBCreateSession);
 78 if(FAILED(hr))
 79 {
 80  RETAILMSG(1,(TEXT("2==pIDBInitialize->QueryInterface failed: 0x%x/r/n"),hr));
 81  goto CleanExit;
 82 }
 83 // Create a session object. 
 84 hr = pIDBCreateSession->CreateSession(NULL, IID_ITableDefinitionWithConstraints, 
 85  (IUnknown**) &pITbleDefWithConstrt);
 86 if(FAILED(hr))
 87 {
 88  RETAILMSG(1,(TEXT("2==pIDBCreateSession->CreateSession failed: 0x%x/r/n"),hr));
 89  goto CleanExit;
 90 }
 91 // (This sample assumes that we have information about the TestTable table database schema.)
 92 // Prepare the table name DBID as Employees.
 93 TableName.eKind = DBKIND_NAME;
 94 TableName.uName.pwszName = L"TestTable";
 95 // Prepare the list of columns that will get the UNIQUE constraint. 
 96 // In this case, just the iID column. 
 97 ColumnList[0].eKind = DBKIND_NAME;
 98 ColumnList[0].uName.pwszName = L"iID";
 99 // Build the DBCONSTRAINTDESC structure needed to make the 
100 // ITableDefinitionWithConstraints::AddConstraint 
101 // call to add the constraint. 
102 rgConstraintDescs[0].pConstraintID = &ConstraintName;
103 rgConstraintDescs[0].ConstraintType = DBCONSTRAINTTYPE_UNIQUE;
104 rgConstraintDescs[0].cColumns = 1;
105 rgConstraintDescs[0].rgColumnList = ColumnList;
106 rgConstraintDescs[0].Deferrability = 0;  // SQL Server CE constraints are not deferrable.
107 // The following properties are not used in UNIQUE constraints
108 rgConstraintDescs[0].pReferencedTableID = NULL;
109 rgConstraintDescs[0].cForeignKeyColumns = 0;
110 rgConstraintDescs[0].rgForeignKeyColumnList = NULL;
111 rgConstraintDescs[0].pwszConstraintText = NULL;
112 rgConstraintDescs[0].UpdateRule = DBUPDELRULE_NOACTION;
113 rgConstraintDescs[0].DeleteRule = DBUPDELRULE_NOACTION;
114 rgConstraintDescs[0].MatchType = DBMATCHTYPE_NONE;
115 // Add the new constraint
116 hr = pITbleDefWithConstrt->AddConstraint(&TableName, rgConstraintDescs);
117 if(FAILED(hr))
118 { //0x80040e37: Table does not exist.
119  RETAILMSG(1,(TEXT("2==pITbleDefWithConstrt->AddConstraint: 0x%x/r/n"),hr));
120  goto CleanExit;
121 }
122 CleanExit:
123 VariantClear(&dbprop[0].vValue);
124 SysFreeString(dbprop[0].vValue.bstrVal);
125 for (i = 0; i < sizeof(sscedbprop) / sizeof(sscedbprop[0]); i++)
126 {
127  VariantClear(&sscedbprop[i].vValue);
128 }
129 if(NULL != pITbleDefWithConstrt)
130 {
131  pITbleDefWithConstrt->Release();
132  pITbleDefWithConstrt = NULL;
133 }
134 if(NULL != pIDBCreateSession)
135 {
136  pIDBCreateSession->Release();
137  pIDBCreateSession = NULL;
138 }
139  
140 if(NULL != pIDBProperties)
141 {
142  pIDBProperties->Release();
143  pIDBProperties = NULL;
144 }
145 if(NULL != pIDBInitialize)
146 {
147  pIDBInitialize->Release();
148  pIDBInitialize = NULL;
149 }

 

转载于:https://www.cnblogs.com/91program/p/5246526.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
cheat engine 7.3 源码 CE7.3源码 添加暗模式支持(更改设置时重新启动 CE) 所有保存的结果现在显示在发现列表中(可以关闭) 组现在可以支持指点通配符。(只有当字段是适当的指点时才有效) 如果重复定时器尚未完成,可以通过释放密钥和抑制来重复热键 结构解剖添加到地址列表使用地址弦而不是数字,因此符号将被保留 结构解剖现在有一个选项来保存列的先前状态,并显示更易于更改 中鼠标单击现在将结构元素的值复制到剪贴板中 添加 [$LUACODE] 块用于内联 Lua 编码 向 CE 添加了 c 编译器 在自动装配器中添加 [$C] 块。所有 [$C] 方块在执行前合并成一个脚本 添加 [$CCODE] 内联 C 编码的方块 (检查论坛、维基、CE 帕特里翁不和谐或 CE 的 youtube) 添加了 C#编译器(编译器) 添加例程以进行。NET(和单体)方法绕道而行。.NET 信息有一个新的上下文, 您可以在那里为自动组装器创建一个绕行模板 将调用方法添加到 .NET 信息窗口 [禁用] 部分现在可以参考标签、定义、AOBScan 结果和在 [ENABLE] 部分创建的分配 用户定义的符号列表具有 CCode 符号的次要列表 更改地址窗口现在也支持相对偏移 DBVM 速度改进 DBVM 具有额外的安全级别,并添加了dbvm_setKeys,以便轻松更改访问代码 DBVM 现在有一些嵌套 VM 的基本支持 (只有这样你才能运行它们, 还没有修改) 新的调试界面:DBVM 级调试器 改进"查找此地址的访问/写入"性能 解剖代码现在允许您指定自定义范围 如果记录是字符串类型,则地址列表值排序现在按字母顺序对值进行排序 多个条目的下拉列表现在可以同时更改 独立注册窗口现在也显示标志值 如果第一个值大于第二个值,则扫描之间的值现在自动摇号顺序 修复: 修复一些游戏冻结 CE 时,符号访问 Lua 调试现在显示循环变量 几个窗口现在保存他们的位置, 不会被损坏, 如果你不显示他们第一次运行 Ce 使用超时时固定创建阅读和停止 固定拆解 vcvtsi2s 固定比较第一次扫描, 如果它是一个大块, 并使它更有效 切共享:注销已修复 固定组装模组 固定的 ultimap ret 过滤器 固定卢阿管从不呼叫奥纳罗尔 64 位 CE 中的固定 vehdebug 在 32 位目标中将 FPU 寄存器归零 固定 DBVM 查找 AMD 上的访问/写入点 使用单行编辑器时不处理内存记录的固定撤消 加载表时固定隐藏儿童组选项 在中断和跟踪窗口中修复了一些字体问题 固定粘贴六角视图中的其他类型 修复符号加载器完全崩溃在未知 pdb 符号数据 卢亚: 保存表不再要求在表上签名 如果省略按钮列表,消息对话将有效。(然后默认到 mbok) 添加更多自定义按钮 注册系统不再错误出整个脚本的失败。它现在覆盖现有符号 还有很多其他的事情。 新功能: 形式. 保存到流编译 () 编译 () 签名扩展签名表符号列表. 获取模态列表符号列表. 获取模拟列表 memscan. 获取保存的执行处理器 memscan. 获取保存的签名列表保存的处理器类
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值